java将参数传递到主方法
我无法将文件名作为参数传递给main方法。这是我的密码java将参数传递到主方法,java,Java,我无法将文件名作为参数传递给main方法。这是我的密码 import java.io.*; class four { public static void main(String args[])throws IOException{ int i; FileInputStream fin = null; try{ fin = new FileInputStream(args[0]); }catch(FileNotFoundException e
import java.io.*;
class four {
public static void main(String args[])throws IOException{
int i;
FileInputStream fin = null;
try{
fin = new FileInputStream(args[0]);
}catch(FileNotFoundException e){
System.out.println("File not found........");
}catch(IndexOutOfBoundsException e){
System.out.println("Index out of bound........");
}
do{
i = fin.read();
if(i != -1)
System.out.println(i);
}while(i!=-1);
fin.close();
}
}你可以把它们传进来;他们只是没有做你认为他们是
回显命令行参数,您将立即看到您的问题:
for (String arg : args) {
System.out.println(arg);
}
我猜您的文件路径中要么有未缩放的Windows斜杠(“\”)要么有空格
避开斜杠,并将每个文件路径用双引号括起来,这样你的运气会更好。还有什么例外?您在命令行中写了什么?