package chaincode;
import java.io.*;
import java.util.Scanner;
public class read_write {
/**
* 复制文件夹
* @param oldPath 老文件路径
* @param newPath 新文件路径
* @param number 编号
* @throws IOException
*/
public static void copyDir(String oldPath, String newPath, int number) throws IOException {
File file = new File(oldPath);
String[] filePath = file.list();
if (!(new File(newPath)).exists()) {
new File(newPath).mkdir();
}
for (int i = 0; i < filePath.length; i++) {
if ((new File(oldPath + file.separator + filePath[i])).isDirectory()) {
copyDir(oldPath + file.separator + filePath[i], newPath + file.separator + filePath[i]+number,number);
}
if (new File(oldPath + file.separator + filePath[i]).isFile()) {
copyFile(oldPath + file.separator + filePath[i], newPath + file.separator + filePath[i].replaceAll("1.go", "")+number+".go",number);//修改复制的文件名
}
}
}
/**
* 复制文件
* @param oldPath 老文件路径
* @param newPath 新文件路径
* @param number 编号
* @throws IOException
*/
public static void copyFile(String oldPath, String newPath,int number) throws IOException {
File oldFile = new File(oldPath);
File file = new File(newPath);
FileInputStream in = new FileInputStream(oldFile);
FileOutputStream out = new FileOutputStream(file);;
byte[] buffer=new byte[2097152];
while((in.read(buffer)) != -1){
out.write(buffer);
}
}
public static void main(String[] args) throws IOException {
String oldPath = "E:\\test1";
for(int i=1; i <= 1; i++) {
String newPath= "E:\\test2";
copyDir(oldPath, newPath+i, i);
}
}
}
import java.io.*;
import java.util.Scanner;
public class read_write {
/**
* 复制文件夹
* @param oldPath 老文件路径
* @param newPath 新文件路径
* @param number 编号
* @throws IOException
*/
public static void copyDir(String oldPath, String newPath, int number) throws IOException {
File file = new File(oldPath);
String[] filePath = file.list();
if (!(new File(newPath)).exists()) {
new File(newPath).mkdir();
}
for (int i = 0; i < filePath.length; i++) {
if ((new File(oldPath + file.separator + filePath[i])).isDirectory()) {
copyDir(oldPath + file.separator + filePath[i], newPath + file.separator + filePath[i]+number,number);
}
if (new File(oldPath + file.separator + filePath[i]).isFile()) {
copyFile(oldPath + file.separator + filePath[i], newPath + file.separator + filePath[i].replaceAll("1.go", "")+number+".go",number);//修改复制的文件名
}
}
}
/**
* 复制文件
* @param oldPath 老文件路径
* @param newPath 新文件路径
* @param number 编号
* @throws IOException
*/
public static void copyFile(String oldPath, String newPath,int number) throws IOException {
File oldFile = new File(oldPath);
File file = new File(newPath);
FileInputStream in = new FileInputStream(oldFile);
FileOutputStream out = new FileOutputStream(file);;
byte[] buffer=new byte[2097152];
while((in.read(buffer)) != -1){
out.write(buffer);
}
}
public static void main(String[] args) throws IOException {
String oldPath = "E:\\test1";
for(int i=1; i <= 1; i++) {
String newPath= "E:\\test2";
copyDir(oldPath, newPath+i, i);
}
}
}