綁定帳號登入

Android 台灣中文網

tag 標籤: storage

相關帖子

版塊 作者 回覆/查看 最後發表
最新版本簡易ROOT教學! 4.0.3~4.1.2皆可用 attachment digest Galaxy SII I9100 x6260849 2012-3-18 1995 259129 chardman 2018-9-24 20:39
S2 求救 USB STORAGE DAMAGED!!!明明還有好多空間 - [懸賞 33 個碎鑽] 過期未解決懸賞 stefanzzz 2012-12-19 4 833 jasongodwe 2012-12-22 22:58
App2SD - Save phone storage 節省手機儲存(去廣告版) v1.0.10 attachment Android 軟體下載 zaqwert963852 2011-10-14 17 2783 ylunlo 2013-8-16 01:10
開學禮 Arc S cm9 RC0版本發布 Xperia Arc LT15i/LT18i s whhungbill 2012-2-12 11 2392 Jun1210 2012-3-4 22:48
本版置頂 Note 4.0和4.1.2完整ROOT教學8/30新增JZO54K解說●附上ROOT好用 attach_img Galaxy Note N7000 kk3180 2012-6-4 1497 153246 SUKI琪 2017-3-2 13:40
復古拼圖:Cryptica v1.5已付費版 attach_img Android 遊戲下載 yes987789 2012-6-7 11 1368 evan670115 2012-10-15 18:55
50 GB of free cloud storage for your Xperia Sony 手機討論區 PI5_PLAY 2012-7-3 12 1051 marine015 2012-7-9 14:49
internal storage空間不足 RAZR XT910 李小胖 2012-8-14 6 1714 woeppie 2012-8-15 18:13
SMS Backup & Restore Pro 簡訊備份與還原專業版 v5.90 付費版 attachment Android 軟體下載 Nessus 2012-9-8 1 480 kenneth_lau 2012-9-8 08:02
認識POM前必備2wipe Galaxy SIII i9300 大璿 2012-10-16 0 1605 大璿 2012-10-16 01:01
App 安裝器找不到外部記憶卡 GALAXY Note2 N7100 djtai 2012-11-3 7 1943 iapk 2012-11-5 18:11
【11/18】4.1.2 XXELK4 S ROM + S PACK V4.2發佈 attachment Galaxy SIII i9300 低調中的高調 2012-11-21 71 6023 hotdogpeople2 2013-2-27 19:16
[Old version]台灣官方版 4.1.1 ZSDLK2 深度優化 省電順暢 attachment Galaxy SIII i9300 低調中的高調 2012-11-24 69 11721 周波波 2013-3-2 22:14
S2 UNROOT疑問 Galaxy SII I9100 nom60818 2012-12-19 2 887 nom60818 2012-12-20 17:38
關於使用非官方3e recovery還原原廠設定時的問題 Galaxy SIII i9300 linmasaki 2012-12-24 8 1583 linmasaki 2012-12-24 15:57
要刷到4.2.1中間遇到了些問題 Galaxy SII I9100 h94580172 2012-12-30 3 485 jhichineng 2012-12-30 21:49
請問l3刷了cm9之後要怎使用usb mass storage? E400 Optimus L3 sunclown1 2012-12-30 1 1139 jackyuan1204 2013-1-3 14:39
降回4.04 Asus 手機討論區 za1 2013-2-3 14 2673 dh9511dh 2013-4-23 19:03

相關日誌

分享 APP storage 讀寫檔案
jianrupan 2013-10-11 12:35
http://android-deve.blogspot.tw/ 1. 存在手機還是 SDcard Android 可以將檔案儲存在 手機上的記憶體 (Internal Storage) ,或是 外部儲存媒體 SDcard(External Storage) 。 android.content.ContextWrapper 類別中的方法, this 是指該 Activity 。 Context.MODE_PRIVATE 是指該檔案為私有的,只能由該 App 讀寫。另外還有其他指示性的常數,在 Context 抽象類別可以找到以 MODE_ 開頭的常數。 External storage : // 取得外部儲存媒體的目錄 ( 這裡會是 /sdcard) String path = Environment.getExternalStorageDirectory().getPath(); // 檔案路徑,記得要加斜線 ( 這樣 /sdcard/filename) File file = new File(path + "/" + filename); // 讀檔 FileInputStream fin = new FileInputStream(file); // 寫檔 FileOutputStream fout = new FileOutputStream(file); 基本上就是使用原本的 Java.io 裡的類別。這樣檔案會直接儲存在 SDcard 下,或許你會想要建立一個自己 App 使用的目錄,使用的方式如下: // 先取得 sdcard 目錄 String path = Environment.getExternalStorageDirectory().getPath(); // 利用 File 來設定目錄的名稱 (myappdir) File dir = new File(path + "/myappdir"); // 先檢查該目錄是否存在 if (!dir.exists()){ // 若不存在則建立它 dir.mkdir(); } 如此就會有一個 /sdcard/myappdir 的目錄產生。之後你的檔案就可以放在 File file = new File(path + "/myappdir/" + filename); 此外,在使用 External storage 之前,最好先檢查一下外部媒是否存在及能否讀寫。 // 取得外部儲存媒體的狀態 String state = Environment.getExternalStorageState(); // 判斷狀態 if (Environment.MEDIA_MOUNTED.equals(state)) { Log.d(TAG, " 可以讀寫 "); } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { Log.d(TAG, " 只可以讀取,無法寫入 "); } else { Log.d(TAG, " 無法讀寫 "); } 3. 程式碼 實際使用的程式碼寫成方法,方便使用,請依自己的需求修改,如下: Internal storage : // 寫檔 private void writeDataToFile(String filename, String data){ try { FileOutputStream fout = this.openFileOutput(filename, Context.MODE_PRIVATE); fout.write(data.getBytes()); fout.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // 讀檔 private String readDataFromFile(String filename){ String result = null; try { StringBuilder sb = new StringBuilder(); FileInputStream fin = this.openFileInput(filename); byte ; while (fin.read(data) != -1) { sb.append(new String(data)); } fin.close(); result = sb.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } External storage : // 寫檔到 sdcard private void writeToSDcard(String filename, String data){ // 建立自己的目錄 String path = Environment.getExternalStorageDirectory().getPath(); File dir = new File(path + "/movietime"); if (!dir.exists()){ dir.mkdir(); } try { File file = new File(path + "/movietime/" + filename); FileOutputStream fout = new FileOutputStream(file); fout.write(data.getBytes()); fout.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d(TAG, "Write to SDCARD!"); } // 從 sdcard 讀檔 private String readFromSDcard(String filename){ String path = Environment.getExternalStorageDirectory().getPath(); File file = new File(path + "/movietime/" + filename); StringBuilder sb = new StringBuilder(); try { FileInputStream fin = new FileInputStream(file); byte ; while (fin.read(data) != -1) { sb.append(new String(data)); } fin.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Log.d("TAG", "Read from SDCARD: " + json.toString()); return sb.toString(); }
個人分類: 軟體應用|3333 次閱讀|0 個評論