Android 讀寫檔案轉為String

2021-08-04 23:05:23 字數 713 閱讀 6920

1.寫入檔案中

string filepath = environment.getdatadirectory()+"/test";

private void writedata()

fileoutputstream outstream = new fileoutputstream(file,true);

outstream.write(str.getbytes());

if(filehascontent())

outstream.close();

} catch (exception e)

}

fileoutputstream outstream = new fileoutputstream(file,true);
第二個引數代表是否要在檔案的後面追加,true為在檔案的末尾追加,false則會將原來的內容給替換掉

outstream.write("/".getbytes());
每寫入乙個內容用乙個「/」分隔開。

2.讀檔案並將檔案內容轉為string和string兩種。

private string readdata()

}catch (exception e)

return false;

}

android 檔案讀寫

檔案的寫 android預設是放在data data 工程包名 files 檔名 第一步 取得檔案的輸出流 是檔案的模式 fileoutputstream outstream context.openfileoutput filename,context.mode private 第二步 資料寫入到...

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