File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing into the previous line

 
Anandh Ramesh
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i have a problem in file handling. i have to read a file for a text pattern, and whenever it is encountered, i have to insert a line of text before it, and a line of text after the pattern. how do i go about it?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You read one file and write a second file. When you read text that doesn't match the pattern, you copy it unchanged to the second file. When you do match the pattern, you write the data you describe in your message. Finally, you rename the original file, rename the new file to the original name, and delete the original file.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if....



This approach may need some kind of synchronization in a multithreaded environment.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic