2014-03-24 34 views

回答

1

您不能FileChannel做到这一点,你可以使用Apache公地IO:

IOUtils.copy(new FileInputStream(file), new FileOutputStream(file2)); 
// copy file and preserve the time stamp. the sourceFile and destFile are of type java.io.File 
FileUtils.copyFile(sourceFile,destFile); 

参考:http://www.studytrails.com/java-io/file-copying-and-moving-deleting.jsp

+0

不...不会...不会复制属性...时间戳是,但只有时间戳 – fge

1

这不是FileChannel的作用。 A FileChannel只是一个字节通道的封装。

你想要的是为此使用“新”Java 7文件API。如果您想将文件复制到一个位置,同时保留的属性,你可以做到这一点:

​​