So I have this .jar file that I am trying to run through Windows 7 Command Prompt. I can get it running with the command java -jar myJar.jar, and it starts to run. I then ask the user to input the file name (for testing purposes this is testFile1.asm), and it shows the following message:
(The filename, directory name, or volume label syntax is incorrect)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)
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. And in case it's relevant, here's my java class.
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();
}
}
for
cycles are used when you know exactly how many times the block has to be executed, it is a nonsense to use them without an end condition and using abreak
into them. Use awhile
instead. – BackSlash