Java实现复制并修改部分⽂件后缀名
public class Test {
public static String DIR = "e:\\Test\\java";//需要复制的源⽂件地址
costumeplaypublic static String DESTDIR = "e:\\Test\\aaa";//拷贝后存放的地址
public static void main(String[] args) throws Exception {
siuSystem.out.println("开始");
traverFolder(DIR);
jyj组合
System.out.println("结束");t
}
public static void copy(InputStream in, OutputStream out) throws Exception {
byte[] buf = new byte[1024];
int len = 0;
involve
/*读取⽂件内容并写⼊⽂件字节流中*/south china a
bootstrapping
while((len = in.read(buf))!=-1) {
out.write(buf, 0, len);
}
}
public static void traverFolder(String path) throws Exception {
File file = new File(path);
if (ists()) {
File[] files = file.listFiles();
if (files.length == 0) {
奥林匹斯十二神System.out.AbsolutePath() + " 空⽂件夹!");
return;
} el {
imply
for (File file2 : files) {
if (file2.isDirectory()) {
//如果是⽂件夹创建⽂件夹
File str = new AbsolutePath().toString().replace(DIR, DESTDIR));
str.mkdir();
//递归查找该⽂件夹⾥⾯的⽂件
AbsolutePath());
}el {
moonwalking
FileInputStream fis = new FileInputStream(file2);