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

熱點內容
grub2命令行 瀏覽:618
無法獲取加密卡信息 瀏覽:774
雲伺服器網卡充值 瀏覽:509
編程就是軟體 瀏覽:49
伺服器如何添加許可權 瀏覽:437
引用指針編程 瀏覽:851
手機加密日記本蘋果版下載 瀏覽:63
命令行括弧 瀏覽:176
java程序升級 瀏覽:490
排序演算法之插入類 瀏覽:227
gcccreate命令 瀏覽:73
海爾監控用什麼app 瀏覽:64
系統盤被壓縮開不了機 瀏覽:984
linuxredis30 瀏覽:541
狸窩pdf轉換器 瀏覽:696
ajax調用java後台 瀏覽:905
活塞式壓縮機常見故障 瀏覽:614
break演算法 瀏覽:731
換電池的app是什麼 瀏覽:771
單片機ad采樣快速發送電腦 瀏覽:22