• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update file content without rewrite the whole file issue

 
Huan Niu
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!
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE 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 ?
 
Naveen Narayanan
Ranch Hand
Posts: 114
Eclipse IDE Java Tomcat Server
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic