Android中檔案的讀寫操作

2021-07-15 04:44:34 字數 855 閱讀 7660

一、讀取assets目錄下的檔案

try 

} catch (ioexception e)

二、讀取raw目錄下的檔案

try 

} catch (ioexception e)

三、讀取手機儲存檔案(內建)

try  catch (filenotfoundexception e)  catch (unsupportedencodingexception e)  catch (ioexception e)
四、寫入到手機儲存(內建)

try  catch (filenotfoundexception e)  catch (unsupportedencodingexception e)  catch (ioexception e)
五、讀取sdcard儲存檔案

file myfile = new file(sdcard, "this is my file.txt");

if (myfile.exists()) catch (filenotfoundexception e) catch (unsupportedencodingexception e) catch (ioexception e)

}

六、寫入sdcard儲存

file myfile = new file(sdcard, "this is my file.txt");

if (!sdcard.exists())

try catch (ioexception e)

Android中檔案的讀寫操作

一 讀取assets目錄下的檔案 try catch ioexception e 二 讀取raw目錄下的檔案 try catch ioexception e 三 讀取手機儲存檔案 內建 try catch filenotfoundexception e catch unsupportedencodi...

android 檔案讀寫操作

android檔案操作 test in main string filename data data com.example.fileoperation files test.txt string str this is for test string readfiledata filename w...

Python中檔案的讀寫操作

在操作檔案之前先要了解各東西,with python中的上下文管理器。python官方文件 with 語句適用於對資源進行訪問的場合,確保不管使用過程中是否發生異常都會執行必要的 清理 操作,釋放資源,比如檔案使用後自動關閉 執行緒中鎖的自動獲取和釋放等。不使用with f open test.tx...