use*_*221 3 java command-line file
这是我在互联网上找到的用于读取文件行的代码,我也使用eclipse,并在其参数字段中将文件名称作为SanShin.txt传递.但它会打印:
Error: textfile.txt (The system cannot find the file specified)
Run Code Online (Sandbox Code Playgroud)
码:
public class Zip {
public static void main(String[] args){
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
请帮我解释为什么会出现这个错误.谢谢
kha*_*hik 12
...
// command line parameter
if(argv.length != 1) {
System.err.println("Invalid command line, exactly one argument required");
System.exit(1);
}
try {
FileInputStream fstream = new FileInputStream(argv[0]);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get the object of DataInputStream
...
> java -cp ... Zip \path\to\test.file
Run Code Online (Sandbox Code Playgroud)