導航:首頁 > 編程語言 > java獲取後綴名

java獲取後綴名

發布時間:2022-05-01 17:08:28

『壹』 java獲取文件名, 提取字元串中局部字元串。拆分文件名及後綴

正則不是更簡單
([^\\/]+)\.([^\\/]+)
$1是文件名,$2是擴展名 ,下面是Javascript的測試代碼:
<script type="text/javascript">
var a="c:\\windows\\abc.txt";
var reg = /([^\\/]+)\.([^\\/]+)/i;
reg.test(a);
alert(RegExp.$1);
alert(RegExp.$2);
</script>

『貳』 javafile怎樣獲取到file文件名的後綴

演示:

File f =new File("Test.txt");
String fileName=f.getName();
String prefix=fileName.substring(fileName.lastIndexOf(".")+1);
System.out.println(prefix);
}

『叄』 java文件名提取

java獲取文件名方法有三種代碼如下展示:

// 舉例:
String fName =" G:\\Java_Source\\navigation_tigra_menu\\demo1\\img\\lev1_arrow.gif ";

// 方法一:

File tempFile =new File( fName.trim());

String fileName = tempFile.getName();

System.out.println("方法一:fileName = " + fileName);

// 方法二:

fName = fName.trim();

// fileName = fName.substring(fName.lastIndexOf("/")+1);
// 或者
fileName = fName.substring(fName.lastIndexOf("\\")+1);

System.out.println("方法二:fileName = " + fileName);

// 方法三:

fName = fName.trim();

String temp[] = fName.split("\\\\"); /**split裡面必須是正則表達式,"\\"的作用是對字元串轉義*/

//temp[] = [G:, Java_Source, navigation_tigra_menu, demo1, img, lev1_arrow.gif]
System.out.println("temp[] = " + Arrays.toString(temp));
fileName = temp[temp.length-1];

System.out.println("方法三:fileName = " + fileName);

『肆』 java對文件名的幾個操作,獲取文件擴展名,去掉擴展名

/*
*Java文件操作獲取文件擴展名
*
*Createdon:2011-8-2
*Author:blueeagle
*/
(Stringfilename){
if((filename!=null)&&(filename.length()>0)){
intdot=filename.lastIndexOf('.');
if((dot>-1)&&(dot<(filename.length()-1))){
returnfilename.substring(dot+1);
}
}
returnfilename;
}
/*
*Java文件操作獲取不帶擴展名的文件名
*
*Createdon:2011-8-2
*Author:blueeagle
*/
(Stringfilename){
if((filename!=null)&&(filename.length()>0)){
intdot=filename.lastIndexOf('.');
if((dot>-1)&&(dot<(filename.length()))){
returnfilename.substring(0,dot);
}
}
returnfilename;
}

『伍』 java獲取上傳的圖片後綴名出錯 變成.image%3A1245499 請問什麼原因呢怎麼解決呢

應該是文件名出現空格了了,%3A是空格的意思,被轉為unicode編碼了

『陸』 jsp或者JAVA如何獲取文件的後綴名字嗎

public String getFileType(String fileUri){
File file = new File(fileUri);
String fineName = file.getName();
String fileType = fileName.substring(fileName.lastIndexOf(\".\")+1,fileName.length())
return fileType;
}

『柒』 Java Base64 直接獲取文件後綴

import sun.misc.BASE64Encoder; import sun.misc.BASE64Decoder; // 將 s 進行 BASE64 編碼 public static String getBASE64(String s) { if (s == null) return null; return (new sun.misc.BASE64Encoder()).encode( s.getBytes() ); }敞飢搬渴植韭邦血鮑摩 // 將 BASE64 編碼的字元串 s 進行解碼 public static String getFromBASE64(String s) { if (s == null) return null; BASE64Decoder decoder = new BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b); } catch (Exception e) { return null; } }

閱讀全文

與java獲取後綴名相關的資料

熱點內容
如何確認伺服器的光口網卡 瀏覽:243
nb1111y壓縮機性能數據 瀏覽:549
下一代編譯器 瀏覽:131
用什麼app可以查產品批號 瀏覽:436
python自動補齊 瀏覽:904
蘋果wifi安卓怎麼連接不上 瀏覽:934
為什麼有的app只能用蘋果支付 瀏覽:175
手游雲頂文件夾 瀏覽:937
msvc和mingw都是編譯器嗎 瀏覽:425
數控機床編程解析 瀏覽:386
新老鳥虛擬資源網解壓碼 瀏覽:559
如何用域用戶登錄ftp伺服器 瀏覽:23
如何將讀書郎平板升級安卓系統 瀏覽:340
XC16編譯器有免費的嗎 瀏覽:500
編譯和程序編輯 瀏覽:849
androidv4和v7 瀏覽:715
iphoneapp怎麼從文件夾安裝 瀏覽:23
去掉加密平板電腦 瀏覽:380
二叉樹用什麼編譯器寫 瀏覽:327
手機除了主板還有什麼app 瀏覽:186