`
lvxiaoxi
  • 浏览: 18027 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

探索 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#renameTo(File)方法

    java的file rename方法 ...不过后来经常发现问题:File#renameTo(File)方法会返回失败(false),文件没有移动,又查不出原因,再后来干脆弃用该方法,自己实现一个copy方法,问题倒是再也没有出现过。

    java临时文件重命名-Java程序重命名文件或目录.pdf

    java临时⽂件重命名_Java程序重命名⽂件或⽬录 ⽅法java.io.File.renameTo()⽤于重命名⽂件或⽬录。此⽅法需要⼀个参数,即⽂件或⽬录被重命名的名称,重命名成功后返回true,否则 返回false。 演⽰此的程序如下所⽰...

    批量修改文件、图片名称

    // file2.renameTo(new File(imgPath + "\\(顔文字"+(i+1)+")." + rightstr)); file2.renameTo(new File(imgPath +"\\"+ emoStrings[i]+"." + rightstr)); } } } catch (Exception e) { // ...

    android 串口驱动

    /* Missing read/write permission, trying to chmod the file */ Process su; su = Runtime.getRuntime().exec("/system/bin/su"); /*String cmd = "chmod 777 " + device.getAbsolutePath() + "\n...

    ClusterFilePoller:一个简单的 java 文件轮询实用程序,可在具有自动故障转移功能的集群环境中工作

    集群文件轮询器 一个简单的 java 文件轮询实用程序,可在具有自动故障转移的集群环境中工作。 正则表达式匹配文件名 轮询多个文件夹(线程) ... file.renameTo(new File(file.getPath() +

    FileRename:快速重命名文件或文件夹-matlab开发

    .renameTo() 快大约 50%。 [Status, Msg] = FileRename(Source, Dest, [Mode]) 输入: Source:字符串,源文件或文件夹的名称。 考虑 Unicode 和 UNC 路径。 目标:字符串,目标文件或文件夹的名称。 模式:字符串...

    国产纯Java多核体系结构模拟器Archimulator.zip

    Explicit register renaming based on the merged architectural and rename register file model; Single-threaded superscalar out-of-order execution, multithreaded SMT and CMP execution model; Multi-level ...

    thumbnailator java用于图片压缩 生成缩略图 添加水印等

    thumbnailator(包括jar包跟api) java用于图片压缩 生成缩略图 添加...Thumbnails.of(new File("path/to/directory").listFiles()) .size(640, 480) .outputFormat("jpg") .toFiles(Rename.PREFIX_DOT_THUMBNAIL);

    plan_in_GitHub365

    GitHub365计划 此举主要目的是为了复习以前的知识,并对自己的自律进行...RenameMess.java 测试 renameTo 重命名方法 ####2015-1-26 BulbbleSort.java 冒泡排序 ####2015-1-27 duotaiarray-* 多态数组的demo ####2015-

    swing文件拖拽

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.swing.Icon; import ...

    IO输入输出留

    // 测试renameto方法 移动和更改问价名 private static void test3() { File f1 = new File("d:/rand.txt"); File f2 = new File("d:/r.txt"); // 刚改前查看文件是否存在 System.out.println(f1.getName...

    FileOperate文件管理

    Rename/delete a specified file. Copy a specified file to another directory. Copy a specified directory (along with all sub-directories and files) to another directory. Encrypt/decrypt a specified file...

    tModLoader.Windows.v0.11.6.2.7z

    To do this, rename the "Terraria.exe" file in the install folder to "Terraria_v1.3.5.3.exe". Make sure you don't accidentally rename it to "Terraria_v1.3.5.3.exe.exe", this is a common mistake ...

    apktool documentation

    After you find a framework file you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number ...

    Appstart source-archive.zip

    You can rename it to your likings, such as run.jar, start.jar, your_app_name.jar setup the appstart.properties file, specifying the main class to launch and other VM options (see AppstartProperties) ...

    burp suite 1.7.26 破解版 永不过期 burploader unlimited

    - The folder for_windows_if_you_dont_wanna_install_vcredist is for anyone who don't wana install vcredist, please chose the file for x64 or x86, rename to vcruntime140.dll and copy to BurpUnlimited....

    EditPlus 4.3.1256_64位 中文版

    * ‘Upload to a temp file then rename’ ftp option could break symbolic link. * Opening remote file from command line could cause program crash. * Fixes a possible error when using FTP proxy server. *...

    appfuse.tar.gz

    1. Rename appfuse/data/.project file to something else. 2. Go to File -> Import -> General -> Existing Projects and browse to your workspace and the appfuse/data root. Because there is no .project ...

    VB编程资源大全(英文源码 网络)

    It is a complete FTP client that allows you to browse FTP directories, 下载 and upload files, resume broken file transfer, create and remove directories, delete and rename files. All the operations ...

    struts2文件上传,与struts2-xml校验

    struts2文件上传,与xml校验 ... myFile[i].renameTo(tmpFile); } book.setFilename(filename); dao.save(book); BookList = dao.getList(); BookList.get(0).getFilename(); return "save"; }

Global site tag (gtag.js) - Google Analytics