0

Im tring to transfer from a file filein starting at position 1300 (in uint8 pieces) into fileto, using the RandomAccessFile transferFrom function.

fromfile = java.io.RandomAccessFile(ifile, 'rw');
fromchannel = fromfile.getChannel();
tofile = java.io.RandomAccessFile(ofile, 'rw');
tochannel = tofile.getChannel();
tochannel.transferFrom(fromchannel,n,fromfile.length()-n)

tochannel.close();
fromchannel.close();
fromfile.close();
tofile.close();

My output file is just empty tho.

Anyone know what im doing wrong??

Edit 1:

I've changed

tochannel.transferFrom(fromchannel,n,fromfile.length()-n)

to

fromchannel.transferTo(n,fromfile.length()-n,tochannel)

But now the output is printing to the all the file right except for it puts alot of 00 hexadecimals where the header in the original was???

Alex Byasse
  • 322
  • 2
  • 5
  • 16

1 Answers1

1

You want to use transferTo I believe

fromchannel.transferTo(n,fromfile.length()-n,tochannel)

as transferFrom tries to start at position n in the outfile, while transferTo will start at position n in the infile

Scott
  • 57
  • 5
  • Ok, I changed the order tho to fromchannel.transferTo(n,fromfile.length()-n,tochannel). Its working except that the output file has alot of zeros at the start where the deleted header was??? Any Ideas – Alex Byasse Nov 25 '13 at 06:34
  • I'm not sure what would be causing you to get zeros at the start? Switching to a java.io.FileOutputStream might help. – Scott Nov 25 '13 at 06:40