Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to process any random file?  RSS feed

 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to know which is the optimistic and widely used way of processing any file.
Processing in the sense
(1) To read the file
(2) To delete some unwanted content
(3) To append some content
(4) To place the content at some specified location based on index as well as substring
And many more.

As far as I know I can use IO streams to read/ write the file and java.util.regex and java.util.matcher to find and replace expressions.

If I'm not correct, please let me know and also the suitable APIs which are to be used.

Thanks and Regards,
Narendranath
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't think there is an optimal method. It depends on the access patterns of your data and so forth. How often will you be reading, writing, deleting, etc? Maybe thousands of reads for only a couple of writes? How much data is involved?

You check out the java.io package - if RandomAccessFile in there doesn't suit you, maybe you want to check out the New I/O package (java.nio).
 
Naren Chivukula
Ranch Hand
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well! I do only once.
 
Sathya Srinivasan
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on how big the file is. If it's small, it doesn't matter. A simple BufferedReader/PrintWriter combination should do.

If you are replacing words in "War and Peace" you probably want to think of NIO, which is supposed to be better than the ones in java.io pacakage. I have read and written some really big files with the simple BufferedReader/PrintWriter mechanism and haven't had any big issues.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!