I'm working on an android project and I have two objects that I will need to save and read. I've written out the code for one of the objects so far but when I run it I get the error "java.io.FileNotFoundException: tripfile.ser: open failed: ENOENT (No such file or directory)"
I had found this post which had a similar problem, but the solution there doesn't seem to work for me. My code is below.
public class FileHandler {
static Context context;
static String tripFileName = "tripfile.ser";
static String oauthFileName = "oauthFile.ser";
public FileHandler(Context c){
context=c;
File dir = new File(context.getFilesDir() + "C:/Users/M/workspace/NerdRanch/FitTravel");
dir.mkdirs();
File tripFile = new File(dir, tripFileName);
File oauthFile = new File(dir, oauthFileName);
}
public static void writeTrip(Trip curTrip){
Trip trip = curTrip;
FileOutputStream outputStream;
try {
outputStream = context.openFileOutput(tripFileName, 0);
ObjectOutputStream objectStream = new ObjectOutputStream(outputStream);
objectStream.writeObject(trip);
objectStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Trip readTrip(){
Trip t;
try{
FileInputStream inputStream = new FileInputStream(tripFileName);
ObjectInputStream objectIn = new ObjectInputStream(inputStream);
t = (Trip) objectIn.readObject();
objectIn.close();
return t;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
}
Can anyone tell me what I'm doing wrong or point me towards a helpful related post?