• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Update file content without rewrite the whole file issue

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

As you all know, this project doesn't allow you to use database instead of file system.

As far as I know, in java, you can't update only parts of a file without rewriting the whole file content.

So the solution will be read the whole content of the data file into memory, modify it, and then write it back to the file.

Now I am wondering, is there any other solutions to update parts of the file rather than read whole into the memory?

Thanks a lot!
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.RandomAccessFile has all the methods you require surely or am I missing your point ?
 
Ranch Hand
Posts: 114
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can rewrite a part of content in a file.
Go the exact position in the file by seeking and overwrite the required portion .
RandomAccessFile.seek(long pos) and
RandomAccessFile.write(byte[] b)
 
Huan Niu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.

It's helpful.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!