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???

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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
I'm not sure what would be causing you to get zeros at the start? Switching to a java.io.FileOutputStream might help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.