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

How to process any random file?

 
Ranch Hand
Posts: 577
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well! I do only once.
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic