• Post Reply Bookmark Topic Watch Topic
  • New Topic

Text file Parsing, certain line copting and insertion  RSS feed

 
Mutassim hasan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,

I have a text file filled with numeric values, the values are in rows, each line has different number of values,

I need:

1- to delete some values exceeding 295 values in certain rows
2- to copy certain lines and insert the copy under the original line
3- some lines contains three values but I need to cut the first value in the next line and replace it in the previous line as the last value in that line!

I want a guide on how to do, which classes or methods for example? or preferably a draft code.

Appreciate your help

I could not attach the sample of the text file on which I need to process as it does not allow text attachments, however, for helpers please give me your email and I will send it to your email.

Thanks
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to JavaRanch!

We don't provide draft code for you, but we can get you pointed in the right direction. You'll probably want to look at FileReader, BufferedReader, and FileWriter. Also check out the the String.split() method, and Integer.parseInt(). That should get you started. If you get stuck though, post the a code example here and explain to us where you're stuck.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perfect advice Greg. i am working on something similar to the OP's. the things you mentioned are exactly what i have been reading up on lately.

don't forget your file I/O can throw an IOException so you need try, catch and finally blocks. unless you use java 7 which has try-with-resources
 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again
If Randall Twede gives you links to the Java™ Tutorials, so will I: Try this section.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!