Results 1 to 6 of 6

Thread: input from file

  1. #1
    freddyvorhees is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default input from file

    say you input from a file

    "name1 1 2 3 4 5 6"
    "name2 1 2 3 4 5 6"
    "name3 1 2 3 4 5 6
    "name4 1 2 3 4 5 6"
    "name5 1 2 3 4 5 6"
    "name6 1 2 3 4 5 6"


    you want to store "name" as a string, and 1 2 3 4 5 6 as int.

    what functions would you use?

    and what would be the sentinel for the loop?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    >>and 1 2 3 4 5 6 as int
    As one int or as 6 different integers?

    So the "name1" is gong to become just "name"?

    You want to read about the String.split method and learn a few handy regexes.

  3. #3
    freddyvorhees is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    then is still have to convert "1 2 3 4 5 6" into int?
    whats the equivalent of putback(), getline(), and get() in java?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I don't know what the methods you are asking do so I can't say.
    You can read the file using FileReader/BufferedReader combination and then read it line by line using the BufferedReader.readLine() method. To convert from String to int just use Integer.parseInt. Read about all those things in the API specs and in Sun's Java tutorial.

  5. #5
    freddyvorhees is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    thats c++.but is there anyway that i can read it without having to convert it?

  6. #6
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    You can read each whole line into a String, then use Scanner.next() to get the name and Scanner.nextInt() to get each integer.

Similar Threads

  1. Replies: 6
    Last Post: 02-10-2011, 10:55 AM
  2. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 05:01 PM
  3. retain value of input type file in a jsp file while being dynamically generated
    By nidhi c in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 03:21 AM
  4. Taking input from Properties File
    By bugger in forum New To Java
    Replies: 4
    Last Post: 05-07-2008, 10:30 AM
  5. How to call the input value from different file?
    By xiongling in forum Networking
    Replies: 6
    Last Post: 04-07-2008, 11:05 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
  •