
正文
java代码给文件改名字 java怎么给文件改名
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用java线程实现批量修改文件名
; /** * this program TODO * @version * @ausor widjan wu */ package file; import java io File; import java util ArrayList; import java util Scanner; import ncurrent *; public class ChangeFileName { public static void main(String[] args) { Scanner in = new Scanner(System in) System out print( Enter base directory : ) String directory = in nextLine() System out print( Enter key words: ) String keywords = in nextLine() ExecutorService pool = Executors newCachedThreadPool() ChangeName change = new ChangeName(new File(directory) keywords pool) FutureInteger result = pool submit(change) try { System out println(result get() + files were changed ) } catch (ExecutionException e) { e printStackTrace() } catch (InterruptedException e) { } pool shutdown() int largestPoolSize = ((ThreadPoolExecutor) pool) getLargestPoolSize() System out println( largest pool size : + largestPoolSize) } } class ChangeName implements CallableInteger { public ChangeName(File directory String keywords ExecutorService pool) { this directory = directory; this pool = pool; this keywords = keywords; } public Integer call() { count = ; try { File[] files = directory listFiles() ArrayListFutureInteger》 results = new ArrayListFutureInteger》() for (File file : files) { if (file isDirectory()) { ChangeName change = new ChangeName(file keywords pool) FutureInteger result = pool submit(change) } else { count++; String path = file getPath() int index = path lastIndexOf( \\ ) path = path substring( index + ) System out println(path) String oldName = file getName() String fileType = oldName substring(oldName lastIndexOf( )) String newFName = path + keywords + count + fileType; file renameTo(new File(newFName)) } } for(FutureInteger result:results) { try { count +=result get() }catch(ExecutionException e) { e printStackTrace() } } }catch(InterruptedException e) { } return count; } private File directory; private String keywords; private ExecutorService pool; private int count; } lishixinzhi/Article/program/Java/gj/201311/27511
相关问答
Q1: java中上传文件时如何修改文件名
第一步:在你需要的盘里新建文本文档,把你喜爱的内容复制进去,保存
第二步:运行软件,
1.选择文本(TXT)文件所在目录
2.更改输出目录
3.更改参数,也就是软件右上角的那些
记的要将TXT文件前面打上勾,最后点击“制作”就可以了。本软件也支持批量制作.
完成后找到你的保存目录,会出现同一文件名的.jad和.jar两个文件,上传.jar文件到手机就可以了(K700C只支持.jar的JAVA文件)
Q2: java 怎么给文件重命名
File file=new File("D:\\abc.java");
if(file.exists())
{
file.renameTo(new File("d:\\123.txt"));
}
希望对你能有所帮助。
java代码给文件改名字的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java怎么给文件改名、java代码给文件改名字的信息别忘了在本站进行查找喔。







