Results 1 to 6 of 6
  1. #1
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default [SOLVED] How do I read from a text file

    I'm asking this question because I want to learn how to read and write from a text file.

    Let's say I have a text file names.txt that has 1000 names listed 1 name in each row. It is saved in "C:/names.txt".

    I have 3 scenarios:

    1. I want to set each name into an array.
    String[] theNames = new String[1000]

    2. I want to take each name and add "Mr. " before it. Save the new names to the same text file.

    3. Same as #2, except create a new text file (theNewNames.txt) and save the names there.

    ~~~~~~~~~~~~~~

    How would I do each of these?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Have you read the sun IO tutorial? That's where I'd start.

    Oh and 2 and 3 would be the same, I think, only for 2. I'd rename the new file to the old file when done. That way you can rename things on the fly .

  3. #3
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Where would I find the sun IO tutorial? Can you post a link?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by matzahboy View Post
    Where would I find the sun IO tutorial? Can you post a link?
    Sure, but I recommend that you bookmark this page: The Really Big Index

    The specific link is here: Lesson: Basic I/O

  5. #5
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Thank you so much for that really big index link. I'm going to spend a good chunk of time in the next few days, going over a few of the topics. I've been looking for this kind of thing for a while and now I've found it :)

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 04:04 PM
  2. Replies: 40
    Last Post: 07-04-2008, 08:41 AM
  3. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  4. Read file
    By tajinvillage in forum Threads and Synchronization
    Replies: 0
    Last Post: 01-29-2008, 09:10 AM
  5. read txt file
    By sureshsri1981 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-05-2007, 03:49 PM

Posting Permissions

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