java更改文件名代码 java怎么更改文件名
java怎么修改文件名称
public class test1
天涯ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
{
public static void main(String[] args) {
File file=new File("D:/gai.jpg"); //指定文件名及路径
String name="123"; //新文件名字
String filename=file.getAbsolutePath();
if(filename.indexOf(".")=0) {
filename = filename.substring(0,filename.lastIndexOf("."));
}
file.renameTo(new File(name+".jpg")); //改名
}
}
用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
java 修改文件名
java修改文件名可以直接通过右键文件名“Rename”实现。
第一步:找到要修改的文件名位置。
第二步:在文件上右击,选择“Refactor”下的“Rename”。
第三步:输入新文件名后,点击“确定”即可完成修改操作。
java怎样按规定批量修改文件名
java批量修改文件名:
public static void main(String[] args) {
updateFileNames("D:\\jjjj", "第");
}
public static void updateFileNames(String url, String index){
File file = new File(url);
//判断文件目录是否存在,且是文件目录,非文件
if(file.exists() file.isDirectory()){
File[] childFiles = file.listFiles();
String path = file.getAbsolutePath();
for(File childFile : childFiles){
//如果是文件
if(childFile.isFile()){
String oldName = childFile.getName();
String newName = oldName.substring(oldName.indexOf(index));
childFile.renameTo(new File(path + "\\" + newName));
}
}
}
}
文章题目:java更改文件名代码 java怎么更改文件名
URL分享:http://scjbc.cn/article/dodeogg.html