Results 1 to 5 of 5
  1. #1
    welikedogs is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default writing a program to read a specific amount of lines from a file?

    hey my names scott am fairly new to java and am looking for a bit of help.

    Im looking to write a program that reads and prints out the first 10 lines of text from a file. Ive been learning java for around 2 weeks now but cannot find anywhere how to do this. Can somebody give me a hand?

    Thanks allot scott :)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    1. Set a counter to 0.
    2. read a line.
    3. increment the counter.
    4. Is the counter < 10? then go to 2.
    5. PROFIT!

    In other words loop 10 times over a readline.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,965
    Rep Power
    8

  4. #4
    welikedogs is offline Member
    Join Date
    Nov 2010
    Posts
    11
    Rep Power
    0

    Default

    no kevin. earlier i wanted to know how to print a certain amount of lines. now i want to know how to print every other line. Thank you for your help!

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default

    earlier i wanted to know how to print a certain amount of lines. now i want to know how to print every other line.
    That's not what you asked.
    Im looking to write a program that reads and prints out the first 10 lines of text from a file.
    If you don't like to be called a cross poster, you shouldn't have cross posted in the first place.

    db

Similar Threads

  1. Replies: 2
    Last Post: 05-01-2010, 09:16 PM
  2. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  3. writing to specific line in text file
    By mickmos in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 01:01 PM
  4. Writing To A Specific Text File Line
    By mokonji in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 08:13 PM
  5. [SOLVED] Writing ArrayList to Text File on seperate Lines
    By shinjitsunohana in forum New To Java
    Replies: 9
    Last Post: 08-27-2008, 05:53 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
  •