探索 java的File 类 renameTo(File)方法

在使用compass 时,发现重建索引重命名文件失败,看了源码,原来源码用了 File renameTo的方法,于是自己做了试验,结合网上一位朋友的帖子
http://xiaoych.iteye.com/blog/149328
下面看我的测试:
                boolean renamed = false;
		 File renameToIndexPathFile;
		 String path = "D:/apache-tomcat-7.0.6/webapps/cc/index/advertset";
		 File indexPathFile = new File(path);
		 int count = 1;
		 renameToIndexPathFile = new File(path + "-copy" + (count++)); 
		 renamed = indexPathFile.renameTo(renameToIndexPathFile);		 
		 System.out.println(renamed);


如果把上面代码的path 间隔符改成下面就成功了:
 String path = "D:\\apache-tomcat-7.0.6\\webapps\\cc\\index\\advertset";

你可能感兴趣的:(java,File)