【发布时间】:2014-06-09 13:01:53
【问题描述】:
嘿,我想保存数据,然后我想阅读它们并将它们放入 EditText 中
speichern.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
save();
tv.setText("gespeichert");
}
});
private void save() {
try {
File myFile = new File("bla.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(string.toString() + "\n");
myOutWriter.append(string2.toString());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Gespeichert",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
private void read() { int bla; StringBuffer strInhalt = new StringBuffer(""); try { FileInputStream in = openFileInput("bla.txt");
while( (bla = in.read()) != -1)
strInhalt.append((char)bla);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我可以改变什么?` 请帮帮我 我正在使用日食 我想保护 .txt 而不是外部的。
【问题讨论】:
-
您是否遇到任何错误?如果是这样,你能提供堆栈跟踪吗? :)
-
当我按下加载时,我得到 android.content.res.Resources$NotFoundException: String resource ID #0x0
标签: java android eclipse load save