java的FileCopy
时间: 2023-11-12 17:57:59 浏览: 113
FileCopy.java
Java中的FileCopy可以使用Java IO中的InputStream和OutputStream来实现。具体实现方式如下:
```java
public static void copyFile(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(source);
os = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
} finally {
is.close();
os.close();
}
}
```
这段代码会将源文件复制到目标文件中。
阅读全文