java - 无法从命令提示符打开.asm文件?

时间:2013-03-13 01:41:04

标签: java jar command-prompt executable-jar

所以我有这个.jar文件,我试图通过Windows 7命令提示符运行。我可以使用命令java -jar myJar.jar运行它,它开始运行。然后我要求用户输入文件名(出于测试目的,这是testFile1.asm),它显示以下消息:

(文件名,目录名或卷标语法不正确)asm
at java.io.FileInputStream.open(Native Method)
在java.io.FileInputStream。(init)(未知来源)
在java.io.FileInputStream。(init)(未知来源)
在java.io.FileReader。(init)(未知来源)
在Assembler.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();
  }
}

2 个答案:

答案 0 :(得分:0)

这就是界限:

if (x == -1 || x == 10){

InputStream API

  

public abstract int read()

     

返回:       数据的下一个字节,如果到达流的末尾则为-1。

打印url的值以确保。

read()方法甚至返回您输入的新行字符。这在Windows和Linux中的处理方式不同。使用BufferedReader并尝试readLine()方法或类似方法。

答案 1 :(得分:0)

在Windows上是CR LF(ascii 13,然后是ascii 10)。在linux和cygwin中,只是LF。所以你需要检查x == 13。

相关问题