• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

lines problem in a file.txt

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am having difficulties to write a code that will tell me the amount of lines within 2 files.

I am using nextline() to detect the lines from the 2 files, but when i want to go back to the top of the file and edit something, it wont allow me since i am already at the bottom of the text file.

How would i get around this problem, to check the lines, if its the same on both files?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to know how many lines are in a file, you read that file, a line at a time, and keep a count as you go.

If you want to edit the file, you read the file in, change the lines you want to change, and write the file back out.

You can do both at the same time if the editing doesn't depend on the number of lines. If it does depend on it, then you'll have to make two passes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic