谁能说出为什么会出现此错误,因为如果您将工作放在终端中?这是代码。
我使用此代码编译文件夹中的所有文件。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Compiles {
public static void main(String[] args) {
List<String> compileFileCommand = new ArrayList<String>();
List<String> files = new FileList().getListFile();
List<String> libs = new ListLib().getListFile();
compileFileCommand.add("/opt/java/bin/javac");
for(int i = 0; i < files.size(); i++)
{
if(files.get(i).equals("Compiles.java"))
continue;
if(files.get(i).equals("Compile.java"))
continue;
String fileJar = new CreateFolder().currentData() + "/" + files.get(i) + " -cp lib/";
// for (int y = 0; y < libs.size(); y++)
// {
// fileJar += libs.get(y) + ":";
// if(libs.size() -1 == y)
// fileJar += libs.get(y);
// }
fileJar += libs.get(0);
compileFileCommand.add(fileJar);
Process compile_process;
try {
compile_process = new ProcessBuilder(compileFileCommand)
.redirectErrorStream(true).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
try {
compile_process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
compile_process.getInputStream()));
String line = null;
try {
line = reader.readLine();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
while (line != null) {
System.out.println(line);
try {
line = reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
错误如下
javac: invalid flag: temp_11.07.2012/CreateFolder.java -cp lib/gdata-media-1.0.jar
Usage: javac <options> <source files>
use -help for a list of possible options
这些是数据示例,这就是给出的