Is there a way where I can serialize my object to a spesific directory?
For example on the Desktop? I don't want the object to be serialized to the project's folder.
Thanks!
Is there a way where I can serialize my object to a spesific directory?
For example on the Desktop? I don't want the object to be serialized to the project's folder.
Thanks!
What have you tried? You should just be able to specify the full path to the file you want to write when you create a FileOutputStream.
puzzleToExport = p;
String filename = pname + ".ser";
try{
FileOutputStream fos = new FileOutputStream(filename);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(puzzleToExport);
oos.close();
System.out.println("puzzles serialised");
}
catch (Exception e){
e.printStackTrace();
}
Should I set the directory on FileOutputStream fos = new FileOutputStream(filename); ??
Read the docs of FileOutputStream constructor then you tell us.
Should I set the directory on FileOutputStream fos = new FileOutputStream(filename); ??
http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html