问题描述
- 请求各位大吓告诉我一下为什么会报异常
-
package IODemo;
import java.io.*;
import java.util.*;
public class TestFileOBJ {
public void FileInformation(File f){
System.out.println("getName="+f.getName());
System.out.println("getPath="+f.getPath());
System.out.println("getAbsolutePath="+f.getAbsolutePath());
System.out.println("getParent="+f.getParent());
System.out.println("length="+f.length());
System.out.println("lastModified="+new Date(f.lastModified()));
}
public void DirectoryInformation(File d){
System.out.println("Dir.getName="+d.getName());
System.out.println("Dir.getParent="+d.getParent());int i=0; String it[]=d.list();//列出文件与子目录 while(i<it.length){ System.out.println("Files="+it[i]); i++; } } public static void main(String[] args){ File f=new File("E://IOdemo","Fileln.java"); File d=new File("E://IOdemo//IOdemo"); File d1=new File("E://IOdemo//Demo01"); TestFileOBJ fo=new TestFileOBJ(); System.out.println("File.information:"+f.getAbsolutePath()); System.out.println("================================"); fo.FileInformation(f); System.out.println("================================"); System.out.println("Directory information:E:\javalianxi\Bark"); System.out.println("================================"); fo.FileInformation(d); fo.DirectoryInformation(d); System.out.println("================================"); d1.mkdir(); }
解决方案
19行,空对象,调试就知道了
解决方案二:
试试这样写
File d=new File("E://IOdemo//IOdemo//");
File d1=new File("E://IOdemo//Demo01//");
时间: 2025-01-27 13:37:37