我先把txt文本考拷到了工程文件里面,想要在项目里面用代码直接读取和进行增删。在网上看到了FileOutputStream outStream = this.openFileOutput("itcast.txt", Context.MODE_PRIVATE);
可以。不过,具体怎么读取,增删(必须是每个activity都能够访问),不知道怎么办高手能不能给点源码。。
另外,还有另一种方法可以解决我的问题,我把东西都放到了string。xml里面,如果能够直接读取和增删xml文件也可以,请高手指教!
可以。不过,具体怎么读取,增删(必须是每个activity都能够访问),不知道怎么办高手能不能给点源码。。
另外,还有另一种方法可以解决我的问题,我把东西都放到了string。xml里面,如果能够直接读取和增删xml文件也可以,请高手指教!
http://www.iteye.com/topic/285062
http://tdq222.iteye.com/blog/701161
StringBuffer sb = new StringBuffer();
BufferedReader buffer = null;
String line = null;
try {
buffer = new BufferedReader(new InputStreamReader(result));
while ((line = buffer.readLine()) != null) {
sb.append(line);
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
String str = "写入字符串";
OutputStream os = openFileOutput("test.txt", MODE_PRIVATE);
os.write(str.getBytes());
os.flush();读操作
InputStream is = openFileInput("test.txt");
int len = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while(true){
byte[] datas = new byte[1024];
len = is.read(datas, 0, 1024);
if(len < 0 )
break;
else{
baos.write(datas, 0, len);
}
}
baos.close();
is.close();
String strRead = new String(baos.toByteArray());