五一在家,学了SQLite和SharedPreferences,刚刚练了下Android的文件存储
读文件:
Context.openFileInput(String fileName)打开一个文件
FileInputStream is = this.openFileInput("test.txt");
is=this.getResources().openRawResource(R.raw.weakcover);
我遇到个问题就是我的文件放在raw文件夹下,但是当我向文件写数据的时候,数据时保存在模拟器中的data文件下的test.txt中,没有同步更新到raw下的文件中.
写文件:
Context.openFileOutput(String name,int mode) 当文件不存在时该文件将被创建
FileOutputStream out=this.openFileOutput("test.txt",MODE_APPEND);
读数据的时候跟java的一样,照搬,哈哈
is=this.getResources().openRawResource(R.raw.weakcover);
StringBuffer bfReadStr=new StringBuffer("");
byte[] buffer=new byte[1024];
int ch=0;
while((ch=is.read(buffer))!=-1){
bfReadStr.append(new String(buffer,"UTF-8"));
}