Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
Apparently nio does not really like to work here:-( I tested this on SuSE 9.1pro (with stock kernel) but we had problem reports from a Mandrake 10 user (with 2.6.* kernel too). Thanks, -- Marco marco@linux:/tmp> cat FileCopyTest.java import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class FileCopyTest { public static void main(String[] args) { File a = new File("/tmp/a"); File b = new File("/tmp/b"); copyFile(a, b); } // end of main() public static void copyFile(File source, File dest){ try { FileChannel in = new FileInputStream(source).getChannel(); if(!dest.getParentFile().exists()) dest.getParentFile().mkdirs(); FileChannel out = new FileOutputStream(dest).getChannel(); in.transferTo(0, in.size(), out); in.close(); out.close(); } catch ( IOException e ) { e.printStackTrace(); } } } marco@linux:/tmp> cp -p ~/snapshot1.png /tmp/a marco@linux:/tmp> java FileCopyTest java.io.IOException: Invalid argument at sun.nio.ch.FileChannelImpl.transferTo0(Native Method) at sun.nio.ch.FileChannelImpl.transferToDirectly(FileChannelImpl.java:392) at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:487) at FileCopyTest.copyFile(FileCopyTest.java:21) at FileCopyTest.main(FileCopyTest.java:13) marco@linux:/tmp> type java java is hashed (/usr/lib/java/bin/java) marco@linux:/tmp> java -version java version "1.4.2_03" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02) Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode) marco@linux:/tmp> ~/Creator/java/bin/java -version java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode) marco@linux:/tmp> ~/Creator/java/bin/java FileCopyTest java.io.IOException: Invalid argument at sun.nio.ch.FileChannelImpl.transferTo0(Native Method) at sun.nio.ch.FileChannelImpl.transferToDirectly(FileChannelImpl.java:392) at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:487) at FileCopyTest.copyFile(FileCopyTest.java:21) at FileCopyTest.main(FileCopyTest.java:13) marco@linux:/tmp> uname -a Linux linux 2.6.4-54.5-bigsmp #1 SMP Fri May 7 21:54:56 UTC 2004 i686 i686 i386 GNU/Linux marco@linux:/tmp> cat /etc/SuSE-release SuSE Linux 9.1 (i586) VERSION = 9.1 ###@###.### 2004-06-02
|