Home  >  Article  >  Java  >  Use the renameTo method to modify the name of the folder in the java web project under linux

Use the renameTo method to modify the name of the folder in the java web project under linux

PHP中文网
PHP中文网Original
2017-06-20 11:37:511714browse

After testing, it is feasible to install tomcat in the Linux environment and then start the project. It is feasible to use the java.io.File.renameTo(File dest) method in the project.

Previously, the code could be modified when running locally, but the function could not be implemented when transferred to the Linux server. I had been tinkering with it, thinking it was due to the difference between the window environment and the Linux environment. Later, I discovered that the renameTo method was used in the project. Modifying the folder name does not work because the js in the java web project was changed before. The value is passed in the js to the background, and the background modifies the folder name based on the value. Because the cache was not cleared, the code in js was not refreshed, so errors kept appearing.

 1   /** 2      * 更改文件夹名称 3      * @param oldName 旧的路径+文件夹名 4      * @param newName 新的路径+文件夹名 5      */ 6     public void renameFile(String oldName,String newName){ 7         File newFile = new File(newName); 8         File oldFile=new File(oldName);//旧的文件夹必须存在 9         boolean result=oldFile.renameTo(newFile);10         if(result){11             LogLog.debug(oldName +" -> "+ newName);12         }else{13             LogLog.error("Failed to rename["+oldName+"] to ["+newName+"].");14             }15         }16     }

The above is the detailed content of Use the renameTo method to modify the name of the folder in the java web project under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn