版权声明:内容记录学习过成文章,仅供参考 https://blog.csdn.net/qq_40195958/article/details/79928932
copy文件到另一个目录下
public static void main(String[] args) {
File file = new File("E:\\830\\");
String fileName = "123456.csv";
File[] fileList = file.listFiles();
auto:
for(int i=0;i<fileList.length;i++){
//System.out.println(fileName.equals(fileList[i].getName()));
if(fileName.equals(fileList[i].getName())){
try {
FileInputStream input = new FileInputStream("E:\\830\\"+fileList[i].getName());
FileOutputStream output = new FileOutputStream("E:\\830copy\\"+fileList[i].getName());
byte[] buffer = new byte[1024];//可以限定每次读多少
int in;
// 限定读取
while((in = input.read(buffer)) != -1){
output.write(buffer,0,in);
}
// 每次读取一个数据字节
// while((in = input.read()) != -1){
// output.write(in);
// }
input.close();
output.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//fileList[i].delete();//读取后删除该文件
continue auto;
}
}
}
- 此方法使用于少量的文件操作还好,如果文件多存在延迟