所以我有这个 .jar 文件,我试图通过 Windows 7 命令提示符运行它。我可以使用命令 java -jar myJar.jar 让它运行,它开始运行。然后我要求用户输入文件名(出于测试目的,这是 testFile1.asm),它显示以下消息:
(文件名、目录名或卷标语法不正确)asm
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(init)(Unknown Source)
at java.io.FileInputStream.(init )(Unknown Source)
at java.io.FileReader.(init)(Unknown Source)
at Assembler.firstPass(Assembler.jgava:33)
at Assembler.main(Assembler.java:29)
它在我的 Linux 终端上运行良好,但我需要让它在 Windows cmd 上运行,这样我的教授才能看到它工作正常。如果它是相关的,这是我的java类。
import java.io.*;
public class Assembler {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
int x;
System.out.println("Please enter a file name.");
String file ="";
for(int i = 0; ;i++){
x = System.in.read();
if (x == -1 || x == 10){
break;
}
file = file + (char)x;
}
firstPass(file);
}
static private void firstPass(String url) throws FileNotFoundException, IOException{
BufferedReader reader = new BufferedReader(new FileReader(url));
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("symbol_table.txt"), "utf-8"));
int LC = 0;
String currLine = reader.readLine();
while(currLine != null){
if(currLine.charAt(3) != ','){ //No Label present
if(currLine.contains("ORG")){ //ORG is present
LC = Integer.parseInt(currLine.substring(9,12));
LC++;
}
else if(currLine.contains("END")){
//secondPass();
break;
}
else {
LC++;
}
}
else{ //Label is present
writer.write(currLine.substring(0,3) + " " + LC +"\r\n");
LC++;
}
currLine = reader.readLine();
}
writer.close();
}
}