Atitit.軟體開發概念說明--io系統區--特殊檔案名稱儲存最佳實務檔案名稱編碼...filenameEncode

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   os   ar   使用   for   

Atitit.軟體開發概念說明--io系統區--特殊檔案名稱儲存最佳實務檔案名稱編碼...filenameEncode

 

不個網頁title儲存成個個檔案的時候兒有無效字元的問題...

 

通常兩個處理方式::: replace 成個空格或者使用轉義(推薦)...

 

windows的檔案名稱無效字元.../\:* <>\"| 斜杠,反斜線,冒號,星號,問號,左右的

角括弧,雙引號,樹杠...而且...“.” 一個點和 “..”雙點分別用來表示“目前的目錄”和“父目錄”, 因此它們也不能作為檔案名稱

 

 

Linux的基本上只有反斜線...

 

作者::老哇的爪子Attilax艾龍,EMAIL:[email protected]

轉載請註明來源: http://blog.csdn.net/attilax

 

 

 

 

public static String fileNameEncode(String filenameOri) {

// /\:* <>\"|

if(filenameOri.equals("."))

return "%2E";

if(filenameOri.equals(".."))

return "%2E%2E";

Map<String, String> mp = (Map<String, String>) new ClosureNoExcpt() {

 

@Override

public Object execute(final Object arg0) {

final Map<String, String> mp = new HashMap<String, String>() {

{

this.put("*", "%2A");

 

}

};

final String[] as = strUtil.SplitByNone("/\\:?<>\"|");

 

for (final String s : as) {

try {

mp.put(s, URLEncoder.encode(s, "utf-8"));

 

} catch (final UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

return mp;

}

}.execute(null);

String[] as = strUtil.SplitByNone(filenameOri);

String fname2 = "";

for (String s : as) {

fname2 += mp.get(s) == null ? s : mp.get(s);

}

return fname2;

}

 

 

 

 

Atitit.軟體開發概念說明--io系統區--特殊檔案名稱儲存最佳實務檔案名稱編碼...filenameEncode

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.