1、要求:开启一个文件,一次读取并显示其内的文件属性,包括文件名、文件类型、是否只读、最后修改时间等属性;并实现对文件属性的修改功能。
2、可以参考windows的文件属性功能:

解决方案 »

  1.   

    使用java读取文件的属性,如文件的创建时间等 
    String   path="xxxx.xxx";   
      File   f   =   new   File(path);   
      f.xxxxx()//详见api帮助文档,索引里输入File就可以了。
    你参考一下API 
      

  2.   

    java中对于文件属性的一些操作1. 当Java.io中,如果文件的操作的时候,判断是否隐藏用File.ishiden()
    判断是否只读,可用File.canWrite().
    2. 当要设置是否是可读或者是隐藏时,在java中除了提供File.setReadOnly()外,就无其他方法了。
       所以我们必须到Dos环境下去设置,在java中用Runtime.getRuntime().exec("attrib " + """ + file.getAbsolutePath() + """+ " +R")该方法可以实现。因为路径file.getAbsolutePath()中可能会还有空格,所以必须用引号把它括起来,当作一个参数。这样就可以实现了(1)   设置只读Runtime.getRuntime().exec("attrib " + """ + file.getAbsolutePath() + """+ " +R");(2)   设置可写Runtime.getRuntime().exec("attrib " + """ + file.getAbsolutePath() + """+ " -R");(3)   设置隐藏Runtime.getRuntime().exec("attrib " + """ + file.getAbsolutePath() + """+ " +H");(4)   设置非隐藏Runtime.getRuntime().exec("attrib " + """ + file.getAbsolutePath() + """+ " -H"); 
      

  3.   


    说的很详细了...其他还有些就要lz去查api了
      

  4.   

    public class FileAttrOperation {    public static void main(String[] args) {
            FileAttrOperation a = new FileAttrOperation();
            a.write();    }    public void write() {
            File file = new File(this.getClass().getResource("/").getPath() + "/a.xml");
            System.out.println("getPath:" + file.getPath());
            System.out.println("isHidden:" + file.isHidden());
            System.out.println("canRead:" + file.canRead());
            System.out.println("canWrite:" + file.canWrite());
            System.out.println("canExecute:" + file.canExecute());
            System.out.println("exists:" + file.exists());
            System.out.println("lastModified:" + file.lastModified());
            System.out.println("getName:" + file.getName());
            file = null;
        }
    }测试结果:Compiling 1 source file to D:\NetBean_work\WebApplication1\build\web\WEB-INF\classes
    getPath:D:\NetBean_work\WebApplication1\build\web\WEB-INF\classes\a.xml
    isHidden:false
    canRead:true
    canWrite:false
    canExecute:true
    exists:true
    lastModified:1227787638000(long型)
    getName:a.xml
    成功生成(总时间:0 秒)
      

  5.   

    时间格式转换:
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
           System.out.println("lastModified:" + formatter.format(file.lastModified()));
    测试结果:
            lastModified:2008-11-27 20:07:18
      

  6.   

    java.io.File对象中定义了这一系列属性