Android檔案中文名字儲存間接實現

來源:互聯網
上載者:User

標籤:android   string   

之前做一個東西的時候因為要儲存2000+的漢字筆畫檔案,每個漢字對應相應的筆畫 ,我從網上看過許多中文漢字名的儲存方法都有問題


後來我想到了一個間接實現的方法在windows上把檔案名稱用 URLEncoder.encode(string, "UTF-8");


轉換然後在Android中找中文檔案名稱的時候 例如 大.gif 就同樣把 URLEncoder.encode(“大.gif ”, "UTF-8");

在Android去找轉換後的檔案


下面是java將檔案名稱轉換的代碼:

package ttatx.rename;import java.io.File;import java.io.UnsupportedEncodingException;import java.net.URLEncoder;/*** 檔案 批量重新命名* @author tiyoto**/import java.util.Scanner;public class BatchRenamefile {//輸出日誌public static volatile boolean isDebug = false;public static void main(String[] args) {String desc = "檔案路徑名";File dir = new File(desc);File[] files = dir.listFiles();int count = 0;for(File f : files){if(f.isFile()&& !(".nomedia".equals(f.getName()))){String string=f.getName();try {string = URLEncoder.encode(string, "UTF-8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}f.renameTo(new File(desc+"/"+string));count ++;}}} } 


Android檔案中文名字儲存間接實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.