日期:2014-05-20  浏览次数:20781 次

JAVA内的最简单的IO操作问题
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);
       
   
       
    }
}
哪位达人帮小弟看一下这个程序,为什么创建不也不了文件呢,不胜感激啊  


------解决方案--------------------
new File并不是在硬盘上创建文件,你可以调用create方法来创建,或者当你调用FileOutputStream时系统也会创建
------解决方案--------------------
同意楼上
new File是在内存里创建的
------解决方案--------------------
同意,new File()用来获取文件信息,不能创建新文件
------解决方案--------------------
new File()用来创建一个文件对象,这个时候只是在内存中建立了文件信息,需要将文件对象转换为输出流输出到文件。