欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java字符串切割實例學習(獲取文件名)

 更新時間:2013年12月10日 10:30:40   投稿:zxhpj  
在Java中處理一些路徑相關(guān)的問題的時候,如要取出ie瀏覽器上傳文件的文件名,由于ie會把整個文件路徑都作為文件名上傳,需要用java.lang.String中的replaceAll或者split來處理,下面看看使用方法

上傳文件路徑為:C:/Documents and Settings/collin/My Documents/111-lazyloading.gif,欲取出文件名:111-lazyloading.gif??梢?/p>

復制代碼 代碼如下:

String temp[] = name.split("////");
if (temp.length > 1) {
name = temp[temp.length - 1];
}

regex為////,因為在java中//表示一個/,而regex中//也表示/,所以當////解析成regex的時候為//。

由于unix中file.separator為斜杠"/",下面這段代碼可以處理windows和unix下的所有情況:

復制代碼 代碼如下:

String temp[] = name.replaceAll("////","/").split("/");
if (temp.length > 1) {
    name = temp[temp.length - 1];
}

相關(guān)文章

最新評論