MozTW 討論區 https://forum.moztw.org/ |
|
nsIFile (nsIFilePicker?) 中文檔名換成 "_" https://forum.moztw.org/viewtopic.php?f=18&t=16312 |
第 1 頁 (共 1 頁) |
發表人: | bluelarva [ 2006-11-08, 14:47 ] |
文章主題 : | nsIFile (nsIFilePicker?) 中文檔名換成 "_" |
我電腦運行環境; 英文版winXP sp1, 英文版firefox 1.5.0.7 以下的程序是讓人點擊open按鈕,然後選者文件.整個xul頁面只有一個按鈕和listbox. 代碼: <?xml version="1.0" encoding="UTF-8" ?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <!DOCTYPE window> <window xmlns= "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script> function openFile() { var nsIFilePicker = Components.interfaces.nsIFilePicker; var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); fp.init(window, "Select a File", nsIFilePicker.modeOpenMultiple); var res = fp.show(); if (res == nsIFilePicker.returnOK){ var fileEnum = fp.files; var item = null; var file = null; while(fileEnum.hasMoreElements()) { item = fileEnum.getNext(); file = item.QueryInterface(Components.interfaces.nsIFile); // Fill in information into listbox var cellName = document.createElement("listcell"); cellName.setAttribute("label", file.leafName ); var cellSize = document.createElement("listcell"); cellSize.setAttribute("label", file.fileSize); var cellType = document.createElement("listcell"); cellType.setAttribute("label", "test文件おの태으"); var cellModified = document.createElement("listcell"); cellModified.setAttribute("label", file.lastModifiedTime); var item = document.createElement("listitem"); item.appendChild(cellName); item.appendChild(cellSize); item.appendChild(cellType); item.appendChild(cellModified); var list = document.getElementById("fileList"); list.appendChild(item); } } } </script> <hbox> <button label="Open..." oncommand="openFile()" /> </hbox> <listbox id="fileList" seltype="multiple" flex="1"> <listhead> <listheader label="Name"/> <listheader label="Size"/> <listheader label="Type"/> <listheader label="Modified" /> </listhead> <listcols > <listcol flex="1"/> <listcol flex="1"/> <listcol flex="1"/> <listcol flex="1"/> </listcols> </listbox> </window> 假如我只選取英文文件名,文件名就會無誤的顯示在listbox. cellType欄位只是用來確定xul可以顯示中文. 假如我選取帶有中文名的文件,listbox就不會顯示了.檢查javascript console: 代碼: Error: uncaught exception: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIFile.fileSize]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: chrome://findfile/content/test.xul :: openFile :: line 28" data: no] 所以我把以下幾行的程式comment out. 代碼: var cellSize = document.createElement("listcell");
// cellSize.setAttribute("label", file.fileSize); var cellModified = document.createElement("listcell"); // cellModified.setAttribute("label", file.lastModifiedTime); 現在listbox可以顯示文件名,但所有中文字一律換成"_". 例如;tall高.txt 成了tall_.txt 我不知這問題是出在nsIFilePicker 還是nsIFile.如何解決這問題呢.謝謝 |
發表人: | kourge [ 2006-11-08, 16:41 ] |
文章主題 : | |
這是 nsIFile 丟出來的錯誤,說找不到檔案...可是如果找不到檔案...那檔案怎麼會出現讓人選 <(O_O)>||| 感覺又像是一個編碼問題... |
發表人: | bluelarva [ 2006-11-08, 17:36 ] |
文章主題 : | |
我覺得是因為 nsIFile把檔案名 換成 tall_.txt, 而事實上卻沒這個文件.所以當提取這改名後的文件的屬性時,ff找不到文件. |
發表人: | yuoo2k [ 2006-11-08, 17:53 ] |
文章主題 : | |
可是我在 WinXP SP2 "中文版" 環境下測試看起來蠻正常的耶...QQ ![]() |
發表人: | bluelarva [ 2006-11-08, 21:58 ] |
文章主題 : | |
你好像用的是 Firefox 2.0 啊.可不可說一說你的運行系統? |
發表人: | yuoo2k [ 2006-11-08, 22:56 ] |
文章主題 : | |
bluelarva 寫: 你好像用的是 Firefox 2.0 啊.可不可說一說你的運行系統?
FX 2.0 zh-TW、en-US 跟 FX1.5 zh-TW 我都試過、都正常... 我們的差別中最可能的問題原因是在... 你的是 WinXP SP1 英文版 而我是 WinXP SP2 中文版。 |
發表人: | bluelarva [ 2006-11-08, 23:17 ] |
文章主題 : | |
我剛下了ff2.0. 用ff2.0 沒問題,看來是1.5的unicode support不到位. 太好了. |
第 1 頁 (共 1 頁) | 所有顯示的時間為 UTC + 8 小時 |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |