1、绝对路径和相对路径
D:\IntelliJ IDEA\IdeaProjects\project01\Module01\src\PackageP12>
以上为编译路径,以下为命令行输入
java ReplacePackage.java D:\\PackageP13\\ import imports /**absolutely*/
java ReplacePackage.java PackageP13 imports import /**relatively*/
2、示例
public class ReplacePackage {
public static void main(String[] args) throws Exception {
if (args.length != 3) {
System.out.println("Usage wrong");
System.exit(1);
}
File file = new File(args[0]);
File[] files = file.listFiles();
if (!file.exists()) {
System.out.println(args[0] + " isn't exist");
System.exit(2);
}
for (int i = 0; i < files.length; i++) {
Scanner input = new Scanner(files[i]);
StringBuffer sb = new StringBuffer();
while (input.hasNext()) {
String s1 = input.nextLine();
String s2 = s1.replaceAll(args[1], args[2]);
sb.append(s2 + "\r\n");
}
input.close();
PrintWriter output = new PrintWriter(files[i]);
output.println(sb);
output.close();
}
}
}