Java File类rename时的错误

Wayne posted @ Tue, 11 May 2010 01:15:29 +0000 in Experience , 6675 readers

 前段时间准备把录音文件改名,很自然地,用到了File类里的renameTo方法。这个方法的用法遍地都是,无外乎如是:

 

File oldf=new File(oldpath);
File newf=new File(newpath);

if(oldf.exists){

 if(oldf.renameTo(newf)){
    
    Log.println("修改成功");

  }else{

    Log.println("修改失败");

  }
}

但是,运行之后,发现全部都是修改失败。 上网找了下原因,有人列出renameTo失败的三种情况:

1.源文件不存在

2.目标文件存在

3.文件系统不对

当然,还有人补充了别的一些原因,比如没有修改权限等等。然而,这些对我的情况来说,都不成立。首先我是windows系统的administrator,不存在权限不足的问题;其次,我是在同一个分区的同一个文件夹里改名,也不存在磁盘分区问题;再次,源文件存在而目标文件不存在。这些可能的原因一个都不是,那到底问题出在哪呢?

这个折腾了我很久。直到有一天我想手动改名实验下的时候,发现症结所在了。我的newpath,也就是要改的名字,里面带了“*”号!! 我原本是想用这个作为分隔符的,没想到这个恰好是windows禁用的符号……早知道如此,我直接用“#”号不就完了!!

кредит онлайн said:
Sat, 07 Aug 2021 06:43:31 +0000

These are the poses of the rozrahovani only for live consumers. Oscillations are mute to consume their income, microcredits are seen by all citizens of the community, including students and pensioners. It is necessary to consider the possibility of rejection of positions from the credit history. Private banks are available to some clients, at that time, as many MFOs are ready to view the position for the increase of the listings.

The simplicity of eliminating microposes allows you to use the system in the capacity of a potent financial reserve. You can take a singing bag with a minimum amount of money, but the term may only take 30 days.


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter