我正在尝试将对象(pilotRecord)写入文件并再次读回。我知道我不需要指定路径,因为它是应用程序内部的路径,因此,如果卸载该应用程序,则希望删除所有文件。
这是我的代码:
fileoutputstream = openFileOutput("test1", Context.MODE_WORLD_WRITEABLE);
Log.d(this.getClass().getName(), "loadPilotRecord: "+fileoutputstream.toString());
objectoutputstream = new ObjectOutputStream(fileoutputstream);
Log.d(this.getClass().getName(), "loadPilotRecord: "+objectoutputstream.toString());
objectoutputstream.writeObject(pilotRecord);
objectoutputstream.close();
fileoutputstream.close();
fileinputstream = new FileInputStream("test1");
Log.d(this.getClass().getName(), "loadPilotRecord: "+fileinputstream.toString());
objectinputstream = new ObjectInputStream(fileinputstream);
Log.d(this.getClass().getName(), "loadPilotRecord: "+objectinputstream.toString());
pilotRecord = (PilotRecord)objectinputstream.readObject();
objectinputstream.close();
fileinputstream.close();
我的问题是,在上面的代码的以下行上收到FileNotFoundException:
fileinputstream = new FileInputStream(“ test1”);
我不太确定如何找出正在使用的路径,或者可能还有一个更明显的问题,我只是没有看到。
抱歉,这有点基本,但是我仍在努力寻找自己的脚。
Log.d语句仅输出类名称和ID。
TIA,
皱纹
最佳答案
您是否尝试过使用openfileinput(“ test1)而不是新的FileInputStream(” test1“)?