| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3192 人关注过本帖
标题:为什么renameTo(File)操作失败
只看楼主 加入收藏
tgnian
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2007-4-13
收藏
 问题点数:0 回复次数: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 失败 
2007-12-16 02:46
快速回复:为什么renameTo(File)操作失败
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010617 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved