Results 1 to 2 of 2
  1. #1
    bren is offline Member
    Join Date
    Jan 2013
    Rep Power

    Default 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.



    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){
    	        catch (IOException e) {
    	            System.out.println("IO Error Occurred: " + e.toString());

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: How to store text from a file to arraylist and then into Jtextfields?

    All you are doing in that code is reading the whole file into your array.
    That's it.
    You are not setting any text fields, or even looking for the search value.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How To Store Variables In A Text File That Aren't Constant
    By anthropamorphic in forum New To Java
    Replies: 6
    Last Post: 08-10-2011, 11:56 PM
  2. Store links in text file and read into variables
    By africanhacker in forum New To Java
    Replies: 1
    Last Post: 03-31-2011, 05:18 PM
  3. Store Text-file Into 2D Array
    By benn22 in forum New To Java
    Replies: 20
    Last Post: 03-09-2011, 09:17 PM
  4. Replies: 4
    Last Post: 01-11-2011, 03:31 PM
  5. how to store string in text file
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-03-2009, 06:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts