What method is more efficient for concatenating large files in Java using FileChannels?

TransferTo() can be far more efficient as there is less data copying, or none if it can all be done in the kernel. And if it isn't on your platform it will still use highly tuned code.

TransferTo() can be far more efficient as there is less data copying, or none if it can all be done in the kernel. And if it isn't on your platform it will still use highly tuned code. You do need the loop, one day it will iterate and your code will keep working.

I see... although allocateDirect allocates space directly on the disk, which is better for JVM memory management, the data is still copied from one place to the other. On the other hand, transferTo/From may actually avoid copying those bytes altogether, letting the kernel decide whether the data needs to be actively copied from source to destination, or whether it can just change its information about the location of the bytes on the disk. Is that correct?

– GLaDOS Jun 6 '11 at 17:08 @GLaDOS allocateDirect() does not 'allocate space directly on the disk'. You are confusing direct buffers with mapped buffers. – EJP Oct 18 '11 at 18:08 thanks; So, from what I read after this comment, a mapped buffer is a type of direct buffer representing a memory-mapped region of a file.

Looks like I still have a lot to learn. – GLaDOS Oct 18 '11 at 18:45 By the way, of course you were right about the "one day it will iterate" and it revealed a misunderstanding on my part about FileChannel position(). It seems that when I read documentation the first time round it doesn't sink in: "This method does not modify this channel's position." – GLaDOS Oct 18 '11 at 18:48 ... that is, transferFrom does not modify the position... :-| – GLaDOS Oct 18 '11 at 18:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions