不是这的错把 你看我的结果: D:\exemple>java file enter directory d:\exemple enter file name liuyc.java file not found 我的文件下的确有这个文件 我用引数传递参数 import java.io.*; class fileInfo{ public static void main(String args[]) throws IOException{ File fileToCheck; if (args.length>0) { for (int i=0;i<args.length;i++) { fileToCheck = new File(args[i]); info (fileToCheck); } } else{ System.out.println("No file given."); } } public static void info (File f) throws IOException { System.out.println("Name: "+f.getName()); System.out.println("Path: "+f.getPath()); if (f.exists()) { System.out.println("File exists."); System.out.print((f.canRead() ?" and is Readable":"")); System.out.print((f.canWrite()?" and is Writeable":"")); System.out.println("."); System.out.println("File is " + f.length() + " bytes."); } else { System.out.println("File does not exist."); } } } 运行结果是: D:\exemple>java fileInfo d:\exemple\liuyc.java Name: liuyc.java Path: d:\exemple\liuyc.java File exists. and is Readable and is Writeable. File is 244 bytes. 我真的高不懂上面的那个程序到底是哪错了
c:\exemple 是不是应该为 c:\example
怀疑是不是input.txt.txt啊?刚才运行你的代码了,我这正常,输出“file found”
你看我的结果:
D:\exemple>java file
enter directory
d:\exemple
enter file name
liuyc.java
file not found
我的文件下的确有这个文件
我用引数传递参数 import java.io.*;
class fileInfo{ public static void main(String args[]) throws IOException{
File fileToCheck;
if (args.length>0)
{ for (int i=0;i<args.length;i++)
{ fileToCheck = new File(args[i]);
info (fileToCheck); } }
else{ System.out.println("No file given."); } }
public static void info (File f) throws IOException {
System.out.println("Name: "+f.getName());
System.out.println("Path: "+f.getPath());
if (f.exists()) { System.out.println("File exists.");
System.out.print((f.canRead() ?" and is Readable":""));
System.out.print((f.canWrite()?" and is Writeable":""));
System.out.println(".");
System.out.println("File is " + f.length() + " bytes."); }
else { System.out.println("File does not exist."); } } } 运行结果是:
D:\exemple>java fileInfo d:\exemple\liuyc.java
Name: liuyc.java
Path: d:\exemple\liuyc.java
File exists.
and is Readable and is Writeable.
File is 244 bytes.
我真的高不懂上面的那个程序到底是哪错了