Results 1 to 3 of 3
  1. #1
    jjavaa is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default Read a data from a text file and create an object from these data in this text file

    Hi all.. i have a text file it names "person.txt" ...

    This is content of person.txt :

    ***********
    m 25 68
    g 35 55
    g 23 65
    m 19 56
    m 40 75
    ***********

    if first line is "m" i should create man object, if first line is "g" i should create girl object... other lines show me respectively age and weight.

    How can i slove this problem ??

  2. #2
    rp181 is offline Member
    Join Date
    Mar 2009
    Posts
    70
    Rep Power
    0

    Default

    What did you try?

  3. #3
    jjavaa is offline Member
    Join Date
    Mar 2011
    Posts
    2
    Rep Power
    0

    Default

    try {
    InputStream fis = new FileInputStream("person.txt");
    Scanner scanner = new Scanner(fis);
    while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    String[] pieces = line.split(" ");
    if(pieces == line.split("m ")){
    create man obj.
    }
    if(pieces == line.split("g ")){
    create girl obj.
    }
    }
    scanner.close();
    } catch (Exception e) {
    System.out.println("There has been some error.");
    }

    like this but if not correctly and my think is not correct..

    i couldn't find how can i do...

Similar Threads

  1. Class employee,company,test: Read data from text file.
    By jeskoston in forum New To Java
    Replies: 4
    Last Post: 03-01-2011, 01:50 AM
  2. Replies: 6
    Last Post: 12-01-2010, 05:31 AM
  3. Replies: 0
    Last Post: 11-21-2010, 05:10 PM
  4. Reading data from a text file
    By Cheguvara in forum New To Java
    Replies: 2
    Last Post: 02-02-2010, 02:33 PM
  5. Replies: 40
    Last Post: 07-04-2008, 08:41 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
  •