android檔案操作:
//test in main()
string filename = "/data/data/com.example.fileoperation/files/test.txt";
string str = "this is for test string";
readfiledata(filename);
writefiledata(filename, str);
// read file input stream
file file = new file("/data/data/com.example.fileoperation/test.txt");
fileinputstream fin = new fileinputstream(file);
// code above is equivalent to below:
/* android activity獨有的方法,讀寫檔案程序式自己目錄下的files資料夾,若檔案不存在,則自動建立之;
如我的程式在:/data/data/com.example.fileoperation, 則test.txt檔案在:
/data/data/com.example.fileoperation/files/test.txt
*/ fileinputstream fin = openfileinput(filename);
// write file output stream
file file = new file("/data/data/com.example.fileoperation/test.txt");
fileoutputstream fout = new fileoutputstream(file);
// code above is equivalent to below:
fileoutputstream fout = openfileoutput(filename, mode_private);
sd卡檔案讀寫:
// write sdcard
private void writefilesdcardfile(string filename, string writestr) throws ioexception catch (exception e)
}// read sdcard
private string readfilesdcardfile(string filename) throws ioexception catch (exception e)
return res;
}原文:
Android中檔案的讀寫操作
一 讀取assets目錄下的檔案 try catch ioexception e 二 讀取raw目錄下的檔案 try catch ioexception e 三 讀取手機儲存檔案 內建 try catch filenotfoundexception e catch unsupportedencodi...
Android中檔案的讀寫操作
一 讀取assets目錄下的檔案 try catch ioexception e 二 讀取raw目錄下的檔案 try catch ioexception e 三 讀取手機儲存檔案 內建 try catch filenotfoundexception e catch unsupportedencodi...
Android中的檔案讀寫操作
在android開發中檔案操作使用的其實還是比較高頻的,之前我遇到這種需求都隨便寫寫,對此沒有乙個比較全面的認識,所以想借這篇文章來梳理一遍。由於需要讀寫檔案,這包含了讀寫外部sd card的檔案,所以需要新增對飲的讀寫許可權 1 獲取儲存路徑android可能有兩個地方可以儲存檔案,一是存放在sd...