如何检查文件状态,
可读
可写
还有已经如何检查这个文件已经在使用中了?java.io.File这个对象里好象没有?谢谢

解决方案 »

  1.   

    试一试这两个方法,可以得到文件的读写状态:
    File f = new File();
    f.canRead( );
    f.canWrite( );
      

  2.   

    import java.io.*;
    File f=new File("file.txt");boolean canRead() 
    Tests whether the application can read the file denoted by this abstract pathname. boolean canWrite() 
    Tests whether the application can modify to the file denoted by this abstract pathname. boolean isHidden() 
    Tests whether the file named by this abstract pathname is a hidden file. long lastModified() 
    Returns the time that the file denoted by this abstract pathname was last modified. boolean setLastModified(long time) 
    Sets the last-modified time of the file or directory named by this abstract pathname. boolean setReadOnly() 
    Marks the file or directory named by this abstract pathname so that only read operations are allowed.
      

  3.   

    1.java.io.File.canRead() 
    2.java.io.File.canWrite() 
    3.java.nio.channels.FileLock
      

  4.   

    canRead() 
    和 canWrite().
      

  5.   

    java.lang.Object
      |
      +--java.io.File
    boolean canRead() 
              Tests whether the application can read the file denoted by this abstract pathname. 
     boolean canWrite() 
              Tests whether the application can modify to the file denoted by this abstract pathname. more...
      

  6.   

    File file = new File();
    file.canRead( );
    file.canWrite( );
    至于你说的判断这个文件是不是正在使用中,是不是可以用异常来判断呢?
    有待调查。
      

  7.   

    file.canRead()和file.canWrite()应该是判断该文件的属性,不能判断该文件是否被其它程序锁住。所以好像只能用异常来处理。不知我的想法对否。