利用IO实现文件复制:
public static void main(String[] args) {
File source = new File("C:/Users/86189/Pictures/clipboard.png");
File target = new File("C:/Users/86189/Pictures/clipboard1.png");
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(target);
byte[] b = new byte[1024];
int n = 0;
while ((n = is.read(b)) != -1) {
os.write(b, 0, n);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
FileChannel实现文件复制:(fileChannel是专门用于文件读写的通道,效率更高,使用更简单)
Commens IO组件实现文件复制。。是apach提供的第三方开源包
