java - Update data to file each amount of bytes -
I want to write my content data in every 10kb file in a file. It looks like:
Whatever I tried:
The file is intestust; FileOutputStream Out; File input = new file (file path); Int fileLength = input.length (); Int len = 0; While (Lennon & lt; fileLength) {len + = Reed (bref); // Write out your data. Write (data, 0, data length); // How to proceed Next 10kb is to read ??? }
I wonder if there is no way to move the cursor to the next volume of the bytes?
Update : Thank you for @hhought
, here's my implementation:
file input = new file ( file path); Long file length = input.length (); Byte [] data; Byte [] buff = new byte [data.line]; Long JUMP_LENGTH = 10 * 1024; RandomAccessFile RF = New RandomAccessFile (Input, "RW"); Long step = JUMP_LENGTH + data Length; For (long I = 0; i & lt; file length; i + = phase) {// read in Buffer RF.Sec (i); Raf.read (fond); Raf.seek (i); // Make sure that it is moved to correct the location after writing RF. Write (data); } Raf.close ();
And it worked well.
RandomAccessFile instead of FileOutputStream
This enables you to search for frantic posts
byte [] data = new byte [1024]; RandomAccessFile file = new RandomAccessFile (new file ("name"), "RW"); File.seek (10 * 1024); File.write (data);
Comments
Post a Comment