package 使用FILE类;import java.io.*;
import java.util.*;public class TestFileClass {
  public static void main(String[] args) {
    // Create a File object
    File file = new File("D:\\JAVA\\eclipse\\工作区\\简单输入输出\\us.txt");
    System.out.println("Does it exist? " + file.exists());
    System.out.println("Can it be read? " + file.canRead());
    System.out.println("Can it be written? " + file.canRead());
    System.out.println("Is it a directory? " + file.isDirectory());
    System.out.println("Is it a file? " + file.isFile());
    System.out.println("Is it absolute? " + file.isAbsolute());
    System.out.println("Is it hidden? " + file.isHidden());
    System.out.println("What is its absolute path? " +
      file.getAbsolutePath());
    
    try {
      System.out.println("What is its canonical path? " +
        file.getCanonicalPath());
    }
    catch (IOException ex) { }    System.out.println("What is its name? " + file.getName());
    System.out.println("What is its path? " + file.getPath());
    System.out.println("When was it last modified? " +
      new Date(file.lastModified()));    System.out.println("What is the path separator? " +
      File.pathSeparatorChar);
    System.out.println("What is the name separator? " +
      File.separatorChar);
    
  
    
  }
}
哪位达人帮小弟看一下这个程序,为什么创建不也不了文件呢,不胜感激啊 

解决方案 »

  1.   

    new File并不是在硬盘上创建文件,你可以调用create方法来创建,或者当你调用FileOutputStream时系统也会创建
      

  2.   

    同意楼上
    new File是在内存里创建的
      

  3.   

    同意,new File()用来获取文件信息,不能创建新文件
      

  4.   

    new File()用来创建一个文件对象,这个时候只是在内存中建立了文件信息,需要将文件对象转换为输出流输出到文件。
      

  5.   

    public class File
    extends Object
    implements Serializable, Comparable<File>An abstract representation of file and directory pathnames.
      

  6.   

    现在你只是创建了一个FILE对像.并没有创建文件.如果把你的程序改成这样File file = new File("D:\\JAVA\\eclipse\\工作区\\简单输入输出");还可以创建目录呢.
      

  7.   

    我在网上看到他们也是用的NEW FILE 语句,可是我这就是出错了,那位兄台能给个详细的语句啊,不胜感激啊!
      

  8.   

    File f....
    f.createNewFile();//创建文件
    f.mkdirs();//创建目录
      

  9.   

    ...File file = new File("fileNamePath");
    file.createNewFile();//创文件
    file.mkdirs;//创目录...
      

  10.   

    谢谢各位兄台的帮助,我已经找到原因了,是因为我在那个地方没有那个US文件,我以为那个语句是创建文件.不过还是要感谢各位,分少,请大家就将就一下吧>
      

  11.   

    再次请教各位兄台,在原目录下没有temp.txt件时, File file = new File("D:\\JAVA\\eclipse\\工作区\\简单输入输出\\temp.txt");创建不出文件,而用 FileWriter output = new FileWriter("temp.txt", true);却可以呢?
      

  12.   

    f.createNewFile();//创建文件
    会抛出异常