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 6 of 6

Thread: reading a certain amount of lines from a file?

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default reading a certain amount of lines from a file?

    Hey guys my names scott and this is my first post. I just recently started using java and am still very basic.

    I want to read a certain amount of lines of text from a file. I'm not sure which loop to use can anyone give me a hand ?

    Thanks Scott


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: reading a certain amount of lines from a file?

    What have you tried?

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: reading a certain amount of lines from a file?

    Tried a while loop. But i only know how to scan next line untill there is no more. Im not sure how to read a certain amount of lines. This is what i need a bit of help with.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: reading a certain amount of lines from a file?

    If I want to do something let's say 10 times, there are a few different ways:

    for(int i = 0; i < 10; i++){
       //do something
    }

    int i = 0;
    while(i < 10){
       //do something
       i++;
    }

    Experiment with them.

    Control Flow Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

  5. The Following User Says Thank You to KevinWorkman For This Useful Post:

    welikedogs (November 3rd, 2010)

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: reading a certain amount of lines from a file?


  7. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: reading a certain amount of lines from a file?

    The OP also posted an obscene response on the other forum when called out for cross posting and homework dumping.

    db

Similar Threads

  1. Reading lines of a text file into a string array
    By fortune2k in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 11th, 2010, 11:56 AM
  2. Reading a lines from text file
    By kiran in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 26th, 2010, 10:54 PM
  3. [SOLVED] reading only certain lines from a .txt file
    By straw in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 7th, 2010, 07:49 PM
  4. Reading from a file, multiple lines
    By MysticDeath in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: October 15th, 2009, 02:40 AM
  5. How to assign values from a file to an arraylist of objects?
    By nadman123 in forum Collections and Generics
    Replies: 3
    Last Post: September 15th, 2008, 01:07 PM