Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Building an array from .txt file.

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Building an array from .txt file.

    I am trying to fill an array with words from a text file. Each line in the file has exactly one word.
    I would like to sequentially fill each position in the array with one line/word.
    I planned on using a counter controlled loop to fill each position in the array.
    The only problem is reading a single line at [count] from the text file.
    Any help would be appreciated.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Building an array from .txt file.

    Why would you want to read a line at a given position? Simply read the file sequentially and place them line read into the array sequentially. You need to counter to access the array not the file.
    Improving the world one idiot at a time!

  3. #3
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Building an array from .txt file.

    If you use a FileReader and put that into a BufferedReader, you could use the BufferedReader's readLine method to read only one line of the file at a time.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Building an array from .txt file.

    Or Scanner.
    Improving the world one idiot at a time!

Similar Threads

  1. JSF: Dynamically building SelectItems
    By Tsarin in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: December 4th, 2011, 05:58 PM
  2. Replies: 3
    Last Post: December 2nd, 2011, 11:53 AM
  3. Help, Building List & finding min and max
    By Margaret_Girl87 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 30th, 2011, 07:15 PM
  4. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  5. help building up GUI for poker game
    By Pencil in forum AWT / Java Swing
    Replies: 5
    Last Post: October 26th, 2010, 02:53 PM