Results 1 to 5 of 5
Thread: Unable to create and write files
- 09-04-2010, 12:54 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 28
- Rep Power
- 0
Unable to create and write files
I'm trying to create a save game system for a program I'm making. I'm trying to do this by having the player save their progress to a file with the extension .ksm by writing the player's current data of the currently active "Mission" object (containing everything needed to continue the game from where it was left off) to said file using an ObjectOutputStream. While the program starts up fine and error-free, the data doesn't seem to write.
I double-checked all the directories, and everything was where it should have been, so then I tried commenting out the code that creates a file, manually making one in the directory, and just writing to that. I ran the program, and the file still came up empty. I can't really think of anything else to do, so here's the relevant code:
So, any obvious problems?Java Code:... import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; ... String missiondirectory; Mission misalpha; File testfile; FileOutputStream missionos; ObjectOutputStream missionwriter; ... public MainController() throws IOException { missiondirectory = "c:\\tbsmissions"; testfile = new File(missiondirectory+"outputtest.ksm"); ... misalpha = new Mission(testmap1, players); ... testfile.createNewFile(); missionos = new FileOutputStream(missiondirectory+"outputtest.ksm"); missionwriter = new ObjectOutputStream(missionos); missionwriter.writeObject(misalpha); }
- 09-04-2010, 02:06 AM #2
how about adding
after the writeObject() method call.Java Code:missionWriter.flush(); missionWriter.close();
Other ideas include, its possible Windows [7] now has a default security mechanism to simply not let user applications write to the C:\ location. Perhaps try writing to
new File(System.getProperty("user.home"), "tbsmissions");
- 09-04-2010, 09:51 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 28
- Rep Power
- 0
Hmm, nope, no dice. Any other suggestions?
- 09-04-2010, 09:59 PM #4
By file empty do you mean it has a length of 0.file still came up empty
What is the name of the file written to disk?
Your code suggests this: c:\\tbsmissionsoutputtest.ksm
What code catches any exception thrown by the Constructor?
What does it do if it gets an exception?
Modify the code to use a try{}catch block and add a printStackTrace() to the catch.
- 09-05-2010, 12:55 AM #5
Member
- Join Date
- Jun 2010
- Posts
- 28
- Rep Power
- 0
Similar Threads
-
Unable to lock files on linux using java.nio.channels.FileLock
By sumayaji in forum Advanced JavaReplies: 2Last Post: 07-26-2011, 04:53 PM -
java.lang.OutOfMemoryError: unable to create new native thread
By BigBear in forum Java ServletReplies: 0Last Post: 04-11-2010, 11:14 PM -
unable to import jar files (crystal report 11)
By kishore101 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-25-2009, 07:51 AM -
Can I write code in 2 different files ?
By fartek in forum New To JavaReplies: 2Last Post: 02-14-2009, 03:48 PM -
java.lang.OutOfMemoryError: unable to create new native thread
By jai135 in forum Java ServletReplies: 11Last Post: 09-01-2008, 10:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks