拷贝亿赛通项目
package com.file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* 拷贝亿赛通处理过的java文件
*
* @author Demon-HY
* @date 2019-7-30
*/
public class Main {
private static final String srcDir = "E:\\code\\demon";
private static final String descDir = "E:\\code\\demon2";
private static final String ignoreDir = ".idea|target";
public static void main(String[] args) {
copyFolder(srcDir, descDir);
}
/**
* 复制整个文件夹内容,并将 *.java 改为 *.javac
*
* @param oldPath String 原文件路径
* @param newPath String 复制后路径
*/
private static void copyFolder(String oldPath, String newPath) {
try {
(new File(newPath)).mkdirs(); //如果文件夹不存在 则建立新文件夹
File a = new File(oldPath);
String[] file = a.list();
File temp;
if (file == null) {
return;
}
for (String s : file) {
if (oldPath.endsWith(File.separator)) {
temp = new File(oldPath + s);
} else {
temp = new File(oldPath + File.separator + s);
}
if (temp.isFile()) {
String tempName = temp.getName();
String[] nameSuffix = tempName.split("\\.");
if (nameSuffix.length == 2 && "java".equals(nameSuffix[1])) {
tempName = nameSuffix[0] + ".javac";
}
FileInputStream input = new FileInputStream(temp);
FileOutputStream output = new FileOutputStream(newPath + "/" + (tempName));
byte[] b = new byte[1024 * 5];
int len;
while ((len = input.read(b)) != -1) {
output.write(b, 0, len);
}
output.flush();
output.close();
input.close();
} else if (temp.isDirectory()) {//如果是子文件夹
// 忽略的目录
if (ignoreDir.contains(temp.getName())) {
continue;
}
copyFolder(oldPath + "/" + s, newPath + "/" + s);
}
}
} catch (Exception e) {
System.out.println("复制整个文件夹内容操作出错");
e.printStackTrace();
}
}
}
批量修改目录及子目录下的 *.javac 为 *.java
将复制后的项目拷贝到没有亿赛通的电脑上,这个时候,java文件的后缀都是 .javac,需要将后缀改回来
使用 Windows 的批处理修改文件后缀,将下面内容保存到 文本文件中,修改后缀为 .bat,将文件放到你的项目根路径下双击运行就可以了
@echo off
::对变量动态捕获扩展变化
set strjavac=javac
set strjava=java
SETLOCAL ENABLEDELAYEDEXPANSION
::遍历文件夹下的javac,并把后缀改成java, /r 表示递归遍历子文件夹
for /r %%c in (*.javac) do (
set javacpath=%%c
set javapath=%%c
:: 替换路径中的文件后缀
set "javapath=!javapath:%strjavac%=%strjava%!"
echo !javacpath!
echo !javapath!
:: 通过移动文件的方式修改文件后缀
move !javacpath! !javapath!
)
pause