部分代码如下: class ModifyAttributeAction extends AbstractAction { //修改文件属性
                int times[];
public ModifyAttributeAction() {
    super("修改文件属性"); //调用父类构造函数
     
}
public void actionPerformed(ActionEvent e) {
String filename=jtfPath.getText(); //从输入框得到文件名
File sfile=new File(filename); //实例化一个文件
try{
if (!sfile.exists()){ //如果文件不存在
        showMessage(filename+" 文件不存在."); //显示信息
}
else{
  boolean attribute=sfile.canWrite(); //可写的则返回true否则为false
  if (attribute==true){  //判断是否相等用==.此处应为"=="!!!!
   showMessage("当前属性不是只读");
Runtime.getRuntime().exec("attrib "  + sfile + " +R");  //修改为只读属性
   } else {
    showMessage("当前属性是只读");
   }
  
  
showMessage(sfile.getName()+" 修改属性成功."); //显示信息
}
}

catch (Exception ex){
ex.printStackTrace(); //打印错误信息
}
}
}
 请问如何修改文件的只读属性呢?已经可以判断一个文件是否为只读文件!
谢谢!!!

解决方案 »

  1.   

    --------------------------------------------------------------
    if (attribute==true){  //判断是否相等用==.此处应为"=="!!!!
    ---------------------------------------------------------------
    改为
    if (attribute){ 
    改为RW
    Runtime.getRuntime().exec("attrib "  + sfile + " +RW");  
      

  2.   

    还是不行,能否解释一下Runtime.getRuntime().exec("attrib "  + sfile + " +RW");的意思~` 谢谢
      

  3.   

    -------------------------------------------------------
    Runtime.getRuntime().exec("attrib "  + sfile + " +R");  //修改为只读属性
    -------------------------------------------------------
    照你这个改的啊