package cn.itcast;
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 Test2 {
public static void main(String[] args) throws IOException {
//新旧文件夹路径
File srcDIR = new File("src/cn/itcast");
File destDIR = new File("HAHAHA");
//获取原文件夹下的所有文件对象
File[] file = srcDIR.listFiles();
//遍历数组,依次拿到每一个File对象
for (File oldFile : file) {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(oldFile));
//????
String fileName = oldFile.getName();
//???
File newFile = new File(destDIR,fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));
//读
byte[] bytes = new byte[1024];
int len;
while((len=bis.read(bytes))!=-1){
//写
bos.write(bytes, 0, len);
}
bos.close();
bis.close();
}
}
}
请问大神上面的
//????
String fileName = oldFile.getName();
//???
File newFile = new File(destDIR,fileName);
这两个注释应该写什么啊,程序会写,但是不知道这两句的具体意思,想记得更牢固些,求大神指点!
谢谢 |
|