所以我有這個.jar文件,我試圖通過Windows 7命令提示符運行。我可以使用命令java -jar myJar.jar運行它,並開始運行。然後我要求用戶輸入文件名(用於測試目的,這是testFile1.asm),並顯示以下信息:java - 無法從命令提示符打開.asm文件?
(文件名,目錄名或卷標語法不正確)ASM
在java.io.FileInputStream.open(本機方法)
在java.io.FileInputStream中。(INIT)(未知源)
在java.io.FileInputStream中。(INIT)(未知源)
在java.io.FileReader。(INIT)(未知源)
在彙編.firstPass(Assembler.jgava:33)
在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();
}
}
這是從stdin獲取字符串的冗長方式。你是否證實你傳遞了你認爲你的文件名?該文件是否位於相同的目錄中?您是否考慮到Windows和Linux爲EOL使用不同的字符? (CR訴CRLF) – 2013-03-13 01:58:28
我建議從問題中刪除彙編標記。雖然你似乎正在編寫彙編程序,但這樣的問題與彙編語言編程無關。 – Michael 2013-03-13 06:47:37
當你確切地知道塊需要被執行多少次時,纔會使用'for for'循環,在沒有結束條件的情況下使用它們並在其中使用'break'是無稽之談。改爲使用「while」。 – BackSlash 2013-03-13 16:46:20