Hope you can help here. I want to read a text file which has 6 lines of text into an array. I then want to break out each of the 6 lines and assign each to a different jcombobox. I can do the first two parts –read the file and assign to an array but when I print it out I get multiple loop outputs and I can’t assign the individual lines to individual jcomboboxes. The program reads the first line and assigns nulls to the other 5 lines. It then reads the first and second lines and assigns nulls to the other lines, and so on. My problem is that I need to capture each line to a jcombobox independent of the other lines entries from the array[]. The array capture all the lines as one input. Is there a way to capture each line separately?
----------------------------public void inputFile() throws IOException{ //File reader method FileReader file = new FileReader("c:\\jcboEntries.dat"); BufferedReader br = new BufferedReader(file); String line; String[] lines = new String [6]; for (int i =0; i<6;i++){ line = br.readLine(); lines[i] = line; jcbo1 = lines[0]; jcbo2 = lines[1]; jcbo3 = lines[2]; jcbo4 = lines[3]; jcbo5 = lines[4]; jcbo6 = lines[5]; System.out.println(jcbo1); System.out.println(jcbo2); System.out.println(jcbo3); System.out.println(jcbo4); System.out.println(jcbo5); System.out.println(jcbo6); } if (br = null) br.close(); }
Output:
Selection Number One
null
null
null
null
null
Selection Number One
Selection Number Two
null
null
null
null
Selection Number One
Selection Number Two
Selection Number Three
null
null
null
Selection Number One
Selection Number Two
Selection Number Three
Selection Number four
null
null
Selection Number One
Selection Number Two
Selection Number Three
Selection Number four
Selection Number Five
null
Selection Number One
Selection Number Two
Selection Number Three
Selection Number four
Selection Number Five
Selection Number Six