導航:首頁 > 編程語言 > 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獲取後綴名相關的資料

熱點內容
胸7椎體輕度壓縮 瀏覽:108
sk5伺服器什麼意思 瀏覽:554
什麼是廊坊交警app 瀏覽:294
衣櫃造價演算法 瀏覽:984
默認的web伺服器地址 瀏覽:694
單片機與發光二極體 瀏覽:320
pythonwebmodule 瀏覽:328
空調壓縮機不停了 瀏覽:115
python序列怎麼取 瀏覽:199
線上資料庫加密怎麼查詢 瀏覽:794
js中數據加密 瀏覽:470
穴pdf 瀏覽:549
阿里雲伺服器雲資料庫還需要嗎 瀏覽:146
在程序設計中常用的演算法有哪些 瀏覽:977
為什麼蘇州公積金app一直維護 瀏覽:805
有ip地址但是dhcp伺服器 瀏覽:446
三星手機加密中斷怎麼回事 瀏覽:538
訓練模型init源碼 瀏覽:840
程序編譯是誰的功能 瀏覽:505
qq收藏怎樣設置加密 瀏覽:291