-3

What are the differences between them and how do I choose which one to use ?

WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138

2 Answers2

2

File.renameTo() changes the name of a file. If the target filename is on another filesystem, it may copy the file's contents, but this is platform dependent.

NIO's FileChannel.transferTo() method actually copies the contents (i.e. the bytes) of a FileChannel (e.g. a file) to another location.

So if you are using renameTo() on the same filesystem, no bytes will be read/writen, only the filename in the directory listing will be changed.

Richard Wеrеzaк
  • 1,551
  • 1
  • 13
  • 17
0

Java NIO

1- In Java NIO you can transfer data directly from one channel to another.

2- Data can be transferred using the transferTo(..) and transferFrom(..) methods of the java.nio.channels.FileChannel class.

3- These methods use the underlying optimization of the file system and therefore in certain cases data transfer can be fast, especially for large files. However, note that the implementation is file system specific and it would be false to claim that this method is always faster

File .Rename to

Java.io.File does not contains any ready make move file method, but you can workaround with the following two alternatives : 1 -File.renameTo(). 2-Copy to new file and delete the original file

renameTo does not work if your target path is on a different filesystem. It will simply return false

Digital Alchemist
  • 2,324
  • 1
  • 15
  • 17