确实没有把文件设为writeAble的
呵呵

解决方案 »

  1.   

    那该怎么办呢?Java就这么弱?
      

  2.   

    刚查了一下,还真没找到你想要的方法。不过发现了个问题
    setReadOnly
    public boolean setReadOnly()Marks the file or directory named by this abstract pathname so that only read operations are allowed. After invoking this method the file or directory is guaranteed not to change until it is either deleted or ed to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system. 
    其中这句话until it is either deleted or ed to allow write access. 究竟能否ed to allow write access?
    还是请高人在指点吧
      

  3.   

    Runtime.getRuntime().exec("cmd /c attrib -R e:\\ss.txt");
      

  4.   


    public class DataExportToXML {public ArrayList getFiles(String filePath, String extensName) { ArrayList arrayList = new ArrayList(); //保存文件信息对像 File file = new File(filePath);//建立当前目录中文件的File对象 

    FiterXML fileNameFiter = null;
    File filelist[] = null; fileNameFiter = new FiterXML(extensName); //只显不扩展名为.xtdb的文件
    filelist = file.listFiles(fileNameFiter); //取得代表目录中所有文件的File对象数组 for (int i = 0; i < filelist.length; i++) {
    if (filelist[i].isFile()) {
    FileInformation fileInfo = new FileInformation();//文件信息对像
    fileInfo.setFileName(filelist[i].getName());
    System.out.println(filelist[i].canWrite());
    fileInfo.setCreatDate(new Date(filelist[i].lastModified()));
    arrayList.add(fileInfo);
    }
    }
    return arrayList;
    }
    public static void main(String[] args){
    DataExportToXML aa =new DataExportToXML();
    aa.getFiles("C:\\","xml");

    }
    }这是我的测试类
      

  5.   

    Runtime.getRuntime().exec("cmd /c attrib -R e:\\ss.txt");
    kingfish(八百里秦川@龙城异客) 的主意不错。
      

  6.   

    应是这样:
    Runtime.getRuntime().exec("cmd /c attrib -W e:\\ss.txt");
      

  7.   

    写错, 没有W参数,只有+/- RASH
      

  8.   

    Runtime.getRuntime().exec("cmd /c attrib -W e:\\ss.txt");
    我执行过,没错。
      

  9.   

    一般系统只对文件的可读性进行控制,即使在window下,也没有办法把一个文件设成write-only,可以说文件是默认可写的,这样java中只有setReadOnly就不奇怪了,
    只要文件可读,就可写,所以不需要设置可写属性,多此一举