Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Content format in a text file

 
vinodh kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can some one advice how to approach in java to format the content of a file as mentioned below.

Present:


Output:

 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to read lines of a file? Do you know how to write lines to a file?
The basic algorithm is this:
1) read ====
2) if there are no more lines available abort
3) read 4 lines
4) combine those 4 lines into one line
5) write that line
6) go to step 1

If you use a Scanner the reading and checking can be done using nextLine() and hasNextLine().
 
vinodh kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.
Let me try based on your algorithm and will revert if any problem.


~Vinodh Kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic