• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to read a file line by line?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to be able to read a file, from the file system line by, basically delimited by \n (new line character).
Then I need to get the size of that line in bytes. And then I will do some processing with that line, which is basically appending it to a buffer with some massaging.
What I don't want to do is read the whole file into a String Buffer at one time and then do my parsing with the StringBuffer - the issue is my file could be extremely large and I am supposed to break my processing into chucks when I hit a certain size.
So, in summary, how do I read a file line by line and then get the size in bytes of that line. I am assuming I will use FileReader but I can only find examples that read it in char by char.
Many Thanks
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrap the FileReader in a BufferedReader, and use the readLine() method.
Then, with the String, you can do getBytes and get the size of the byte array that is returned.
 
Gerald Luckenbill
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Super!
Thanks!
 
Always! Wait. Never. Shut up. Look at this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic