Results 1 to 2 of 2
- 01-22-2013, 11:26 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 1
- Rep Power
- 0
How to store text from a file to arraylist and then into Jtextfields?
I would like to store the strings from my file into an ArrayList and then reading the 1st line to textfield1, 2nd line to textfield2, 3rd line line to textfield3.
Basically, i have a search button which searches for the first string and then based on that string it prints the next lines. For instance, if i search for valera1, then i want to read the array and store valera1 in textfield2, valera2 in textfield3, and valera3 in textfield4.
I have tried vector, array, arraylist etc. But nothing seems to work! Please help thanks.
file.txt
valera1
valera2
valera3
luiz1
luiz2
luiz3
So far i have this code below:
Java Code://search by name search.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ try { String stringSearch = textfield1.getText(); BufferedReader bf = new BufferedReader(new FileReader("file.txt")); String line; ArrayList<String> myarray = new ArrayList<String>(); while (( line = bf.readLine()) != null){ myarray.add(line); //textfield2.setText(); //textfield3.setText(); //textfield4.setText(); } bf.close(); } catch (IOException e) { System.out.println("IO Error Occurred: " + e.toString()); } } });
- 01-23-2013, 09:51 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
How To Store Variables In A Text File That Aren't Constant
By anthropamorphic in forum New To JavaReplies: 6Last Post: 08-10-2011, 11:56 PM -
Store links in text file and read into variables
By africanhacker in forum New To JavaReplies: 1Last Post: 03-31-2011, 05:18 PM -
Store Text-file Into 2D Array
By benn22 in forum New To JavaReplies: 20Last Post: 03-09-2011, 09:17 PM -
Extract data from file and store into separate ArrayList
By pawarkomal in forum New To JavaReplies: 4Last Post: 01-11-2011, 03:31 PM -
how to store string in text file
By santhosh_el in forum AWT / SwingReplies: 2Last Post: 04-03-2009, 06:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks