java如何复制文件呢?
下文笔者讲述java复制文件的方法分享,如下所示:
实现思路:
使用FileInputStream和FileOutputStream进行两个流之间的复制
从而达到复制文件的目的
例:文件复制的方法分享
private static void copyFileUsingStream(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();
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


