Serialize Object to specific directory

Started by
4 comments, last by shadowstep00 8 years, 10 months ago

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!

Failure is not an option...

Advertisement

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); ??

Failure is not an option...


Should I set the directory on FileOutputStream fos = new FileOutputStream(filename); ??
Read the docs of FileOutputStream constructor then you tell us.

http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Are you asking how to determine the "project's folder"?

I guess the bigger question might be what are you trying to serialize, settings, save games, something else?

Well that was really dumb of me. I was using \ instead of /, That's why I wasn't able to save the serialized file elsewhere.

FileOutputStream was legit all the way. ^^

My bad, sorry guys. tongue.png

Failure is not an option...

This topic is closed to new replies.

Advertisement