public void TestTransferFrom() {
try {
RandomAccessFile raf = new RandomAccessFile("C:\\Users\\Hajon\\Downloads\\apache-maven-3.3.9-bin.zip", "rw");
FileChannel fromChannel=raf.getChannel();
RandomAccessFile raf1 = new RandomAccessFile("C:\\Users\\Hajon\\Downloads\\apache-maven-3.3-bin.zip", "rw");
FileChannel toChannel=raf.getChannel();
long position=0;
long size=fromChannel.size();
System.out.println(size);
toChannel.transferFrom(fromChannel, position, size);
raf.close();
raf1.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
執行完後的復制結果都是空的怎麼回事
public static void TestTransferFrom() {
try {
RandomAccessFile raf = new RandomAccessFile("D:/eclipse/lib/tuscany-sdo-impl-1.1.1.src.zip", "rw");
FileChannel fromChannel=raf.getChannel();
RandomAccessFile raf1 = new RandomAccessFile("D:/tuscany-sdo-impl-1.1.1.src.zip", "rw");
FileChannel toChannel=raf1.getChannel();
long position=0;
long size=fromChannel.size();
System.out.println(size);
toChannel.transferFrom(fromChannel, position, size);
fromChannel.close();
toChannel.close();
raf.close();
raf1.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
輸出流應該是raf1,而不是還用輸入流。