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怎么更改文件名
網站路徑:http://m.kartarina.com/article16/dodeogg.html

成都網站建設公司_創新互聯,為您提供App設計建站公司標簽優化品牌網站建設網站設計品牌網站設計

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

營銷型網站建設
主站蜘蛛池模板: 精品无码成人久久久久久| 无码福利写真片视频在线播放| 熟妇人妻系列aⅴ无码专区友真希 熟妇人妻系列av无码一区二区 | 无码免费一区二区三区免费播放| 无码视频在线播放一二三区| 中文字幕人妻无码专区| 无码粉嫩小泬无套在线观看 | 日韩精品人妻系列无码专区| 久久久g0g0午夜无码精品 | 在线观看无码的免费网站| 国产午夜无码视频在线观看| 自慰系列无码专区| 亚洲精品无码成人AAA片| 亚洲成av人片天堂网无码】| 亚洲精品无码午夜福利中文字幕| 无码人妻丰满熟妇区96| 日韩精品无码人成视频手机| 免费无码AV电影在线观看| 亚洲精品无码午夜福利中文字幕| 人妻少妇精品无码专区漫画| 无码国产69精品久久久久网站| 日韩少妇无码喷潮系列一二三| 中文无码热在线视频| 无码国产精成人午夜视频一区二区| 精品人妻无码专区在中文字幕| 亚洲av日韩av无码av| 亚洲av专区无码观看精品天堂| 久久伊人中文无码| 亚洲午夜福利精品无码| 日韩精品无码免费视频| 久久无码高潮喷水| 亚洲AV无码成人网站久久精品大| 国产精品无码一区二区三区免费| 伊人久久一区二区三区无码| 亚洲AV永久无码天堂影院| 日韩精品久久无码人妻中文字幕| 亚洲精品无码专区在线在线播放| 久久亚洲精品无码播放| 伊人久久综合精品无码AV专区| 亚洲Av无码乱码在线znlu| 亚洲免费无码在线|