当前位置: 代码迷 >> Java相关 >> 为什么renameTo(File)操作失败
  详细解决方案

为什么renameTo(File)操作失败

热度:187   发布时间:2007-12-16 02:46:06.0
为什么renameTo(File)操作失败
楼主
public void saveAsFile()
    {
        fc.addChoosableFileFilter(filter);
        fc.setDialogTitle("另存为");
        int len=fc.showSaveDialog(NotePad.this);
        if (len == JFileChooser.APPROVE_OPTION)
        {
            file = fc.getSelectedFile();
            String fileName=file.getAbsolutePath();
            int extensionIndex=fileName.indexOf(".txt");
            if (extensionIndex<0)
                {
                String str=fileName+".txt";
                System.out.println(file.renameTo(new File(str)));
                System.out.print(str);
                }
                ........
            try
            {
                BufferedWriter output=new BufferedWriter(new FileWriter(file));
               
                String out=textArea.getText();
                out=out.replaceAll("\n", "\r\n");
                output.write(out);
               
                output.close();
            } catch (FileNotFoundException e1)
            {
                e1.printStackTrace();
            }
            catch(IOException ex)
            {
               
            }
        }
}
一个输出为
false
C:\Documents and Settings\Owner\桌面\w.txt

如renameTo(File)操作成功返回true
为什么renameTo(File)操作失败
搜索更多相关的解决方案: renameTo  File  失败  

----------------解决方案--------------------------------------------------------
  相关解决方案