Java IO流 打印流 PrintStream PrintWriter
Java IO流 序列化流 ObjectOutputStream ObjectInputStream
Java IO流 缓冲流 BufferedInputStream BufferedOutputStream BufferedReader BufferedWriter
Java IO流 字符流 目录拷贝
Java IO流 字符流 FileWriter
Java IO流 字符流 FileReader
Java IO流 字节流 FileInputStream
Java IO流 字节流 FileOutputStream
public class CopyDir {
public static void main(String[] args) throws IOException {
String src = "D:\\xxx";
String dest = "D:\\xxx";
copyDir(new File(src), new File(dest));
}
public static void copyDir(File src, File dest) throws IOException {
dest.mkdirs();
// 查看文件夹下的文件
File[] files = src.listFiles();
// 遍历
for (File file : files) {
if(file.isFile()){
// 如果是文件, 拷贝
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream(new File(dest, file.getName()));
byte[] bytes = new byte[1024];
int len;
while ((len = fis.read(bytes)) != -1) {
fos.write(bytes, 0, len);
}
fos.close();
fis.close();
}else {
// 如果是文件夹, 递归
copyDir(file, new File(dest, file.getName()));
}
}
}
}