该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.io.*;
class fileInfo {
File fileToCheck;
public static void main (String args[]) throws IOException {
if(args.length > 0) {
for(int i=0;i
File 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.getAbsolutePath());
if (f.exists()) {
System.out.println("File exits.");
System.out.print(f.canRead() ? " and is Readable" :"");
System.out.print(f.canWrite() ? " and is Writeable" : "");
System.out.println(".");
System.out.println("File" + f.length() + "bytes.");
}
else {
System.out.println("File not exit.");
}
}
}
这段代码可以显示文件名和路径,为什么打印显示文件不存在?
请高手指点~!