android 檔案讀寫

2021-08-26 11:22:46 字數 650 閱讀 7476

檔案的寫 android預設是放在data/data/工程包名/files/檔名

第一步:

取得檔案的輸出流 是檔案的模式

fileoutputstream outstream = context.openfileoutput(filename, context.mode_private);

第二步:

資料寫入到檔案

outstream.write(content.getbytes());

檔案的讀 android預設是放在data/data/工程包名/files/檔名

第一步:

取得檔案的輸入流

fileinputstream instream = context.openfileinput(filename);

第二步:

讀取檔案內容

byte buffer = new byte[1024];

int len = 0;

bytearrayoutputstream outstream = new bytearrayoutputstream();

while( (len = instream.read(buffer))!= -1)

byte data = outstream.tobytearray();//得到檔案的二進位制資料

Android 讀寫Excel檔案

android 讀寫 excel 檔案 需求背景 最近在做專案過程中,需要讀取 excel 檔案,excel檔案可以來自使用者插在android裝置上的外接u盤,也可以是儲存在專案assets raw裡面。資料參考 查閱了很多相關資料,讀取外接u盤主要用到了android 讀取usb檔案的第三方開源...

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...

android中讀寫xml檔案

android中經常會遇到要讀取或者寫入一些xml檔案,如某些 的請求返回就是xml格式的。這樣,我們得到檔案流可以對xml檔案進行解析,進而得到裡面的一些我們所需要的引數。xml檔案的解析方式有三種 dom document object model sax api for xml 和androi...