What I need to do is to create an array that needs to be filled with the numbers of lines from a text file, so lets say the text file has 5 lines, so the array will be: array [5] I have the following code:
try{ LineNumberReader lnr = new LineNumberReader(new FileReader(new File("lista de numeros.txt"))); int linenumber = 0; int primero = 0;
String tmp = new String();
tmp=lnr.readLine();
while(tmp != null)
{
linenumber++;
JOptionPane.showMessageDialog (null, (tmp));
tmp=lnr.readLine();
} int mitad=(0+linenumber)/2; int [] array = new int[linenumber];
What I want to do is to create the array as it is on the last line from the code, I'm trying that way, but if I try to print something like:
JOptionPane.showMessageDialog (null, "Number at half: " + array[mitad]);
Only shows a 0 : Can someone tell me how can I filled the array in the right way please