java - Writing data to file is erasing everything before it(Placing 00's) and changing the file size -


i have program writes out data- using logic

fileoutputstream outpre = new fileoutputstream(getfile()); filechannel ch = outpre.getchannel(); ch.position(startwr); ch.write(bytebuffer.wrap(dsave)); outpre.close(); 

it writes out correct data correct location, problem before starting location write (startwr) gets replaced 00's, , file changed making point @ writing done, end of file.

how can write data file without corrupting previous data , changing file size?

you need instruct stream either append or overwrite contents of file...

take @ fileoutpustream(file, boolean) more details

updated

after mucking around, found solution close working was...

randomaccessfile raf = null;  try {     raf = new randomaccessfile(new file("c:/test.txt"), "rw");     raf.seek(3);     raf.writebytes("bb"); } catch (ioexception exp) {     exp.printstacktrace(); } {     try {         raf.close();     } catch (exception e) {     } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -