【发布时间】:2014-12-22 03:58:24
【问题描述】:
我正在使用此代码尝试将 int 保存到文件中然后检索它:
ObjectOutputStream oos;
try{
oos=new ObjectOutputStream(new FileOutputStream(new File(getFilesDir()+"hs.dat")));
oos.writeInt(hs);
}
catch (Exception e){}
TextView txtRecord = (TextView) findViewById(R.id.txtRecord);
try{
ObjectInputStream ois=new ObjectInputStream(new FileInputStream(getFilesDir()+"hs.dat"));
hs=ois.readInt();
txtRecord.setText(getString(R.string.recordStr) +" "+ hs);
} catch (Exception e) {
txtRecord.setText(getString(R.string.recordStr) +" "+ "0");
}
即使我知道 int 不是 0,我总是得到“0”,这不是正确的做法吗?
哎哟~
【问题讨论】:
标签: android file android-studio int save