标签:类型 gen try input byte int 创建 tst 代码
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyAll {
public static void main(String[] args) {
//原路径
String oldFile = "";
//新路径
String newFile = "";
//调用拷贝所有文件的方法
copyAll(oldFile,newFile);
}
//定义一个拷贝文件的方法,oldFile-->原路径 newFile-->新路径
public static void copyAll(String oldFile,String newFile) {
try (//创建字节输入缓冲流对象
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(oldFile)));
//创建字节输出缓冲流对象
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(newFile)))
){
//复制,一边读一边写
byte[] by = new byte[1024];
int len;
while((len = bis.read(by)) != -1) {
bos.write(by, 0, len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
}
}
}
标签:类型 gen try input byte int 创建 tst 代码
原文地址:https://www.cnblogs.com/private-mingmie/p/11819002.html