Results 1 to 4 of 4
  1. #1
    Ericyue is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Exclamation read text data and store to array

    hi ,

    i am currently doing a program which it can read the data in the text file and store it to the array

    this is what i have done so far :

    import java.io.*;
    import java.util.*;


    class FileRead
    {
    public static void main(String args[])
    {
    try{

    FileInputStream fstream = new FileInputStream("Data.txt");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;

    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    System.out.println (strLine);

    }
    in.close();
    }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
    }

    can anyone guild me how to improve that ???

    thanks in advance :)

  2. #2
    Ericyue is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Default Re: read text data and store to array

    i will have a Data.txt like this :

    2
    192.168.1.1 ; pc1 ; /home/pc1/Desktop ; C:/home/Documents
    192.168.1.2 ; pc2 ; /home/pc2/Desktop ; C:/home/Documents


    the 2 is to make a array size of 2 and store the certain info into the array that i want .

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default Re: read text data and store to array

    Can you explain what your problems are?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Join Date
    Jul 2011
    Posts
    30
    Rep Power
    0

    Default Re: read text data and store to array

    The variable that you want to manipulate is strLine. Currently you're just printing out it's value to the console. Where you are reading the file line by line think about strLine's value every time it loops and how you can use this to do what you want.

Similar Threads

  1. Read in File and Store it in an Array. Please Help!
    By PurpleDemon666 in forum New To Java
    Replies: 1
    Last Post: 10-21-2011, 08:50 PM
  2. Read xml data with multiple attributes and store values
    By LiveStrong-2011 in forum New To Java
    Replies: 4
    Last Post: 06-08-2011, 12:45 AM
  3. 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
  4. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 06:43 AM
  5. How to read data from excel and store it in db
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-03-2008, 10:19 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
  •