简体   繁体   English

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

[英]java - Can't open .asm file from Command Prompt?

So I have this .jar file that I am trying to run through Windows 7 Command Prompt. 因此,我有一个要通过Windows 7命令提示符运行的.jar文件。 I can get it running with the command java -jar myJar.jar, and it starts to run. 我可以使用命令java -jar myJar.jar使其运行,然后开始运行。 I then ask the user to input the file name (for testing purposes this is testFile1.asm), and it shows the following message: 然后,我要求用户输入文件名(出于测试目的,这是testFile1.asm),它显示以下消息:

(The filename, directory name, or volume label syntax is incorrect)asm (文件名,目录名或卷标签语法不正确)
at java.io.FileInputStream.open(Native Method) 在java.io.FileInputStream.open(本机方法)
at java.io.FileInputStream.(init)(Unknown Source) 在java.io.FileInputStream。(init)(未知源)
at java.io.FileInputStream.(init)(Unknown Source) 在java.io.FileInputStream。(init)(未知源)
at java.io.FileReader.(init)(Unknown Source) 在java.io.FileReader。(init)(未知源)
at Assembler.firstPass(Assembler.jgava:33) 在Assembler.firstPass(Assembler.jgava:33)
at Assembler.main(Assembler.java:29) 在Assembler.main(Assembler.java:29)

It works fine on my Linux terminal, but I need to get it working on Windows cmd so my prof can see that it works. 它可以在我的Linux终端上正常工作,但是我需要在Windows cmd上运行它,以便教授可以看到它的工作原理。 And in case it's relevant, here's my java class. 如果相关,这是我的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();
  }
}

It's the line: 这是一行:

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

From InputStream API InputStream API

public abstract int read() 公共抽象诠释read()

Returns: the next byte of data, or -1 if the end of the stream is reached. 返回:数据的下一个字节;如果到达流的末尾,则返回-1。

Print the value of url to make sure. 打印url的值以确保。

read() method return even the new line character you entered. read()方法甚至返回您输入的换行符。 This is handled differently in Windows and Linux. 在Windows和Linux中,此处理方式有所不同。 Use a BufferedReader and try readLine() method, or something like that. 使用BufferedReader并尝试使用readLine()方法或类似方法。

On Windows is CR LF (ascii 13 then ascii 10). 在Windows上是CR LF(ASCII 13,然后是ASCII 10)。 On linux and in cygwin, is just LF. 在linux和cygwin中,只有LF。 So you need to check x == 13 as well. 因此,您还需要检查x == 13。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM