欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java更改文件名代碼 java怎么更改文件名

java怎么修改文件名稱

public class test1

天涯ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!

{

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線程實(shí)現(xiàn)批量修改文件名

;?? /**??? ??? * 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修改文件名可以直接通過(guò)右鍵文件名“Rename”實(shí)現(xiàn)。

第一步:找到要修改的文件名位置。

第二步:在文件上右擊,選擇“Refactor”下的“Rename”。

第三步:輸入新文件名后,點(diǎn)擊“確定”即可完成修改操作。

java怎樣按規(guī)定批量修改文件名

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));

}

}

}

}

當(dāng)前標(biāo)題:java更改文件名代碼 java怎么更改文件名
網(wǎng)站路徑:http://chinadenli.net/article16/dodeogg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、建站公司、標(biāo)簽優(yōu)化、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)