Urgent deadline - Please help - Linux serialization problem
Hi -
I have a presentation on Wednesday morning of my program for my dissertation. I developed the whole thing in windows - it all works great... but the demo is on a Linux machine. Fortunately I tested today in Linux. I have a real problem. I want to save out a class instance. This code works fine in Windows:
String project_name = f.getAbsolutePath() +"/" + directory_name +".oll";
ObjectOutputStream out =new ObjectOutputStream(new FileOutputStream(project_name));
out.writeObject(mainCanvas);
out.flush();
out.close();
The problem is that in Linux I just don't get anything saved. There is nothing there at all. No file is saved. I cannot work this out and am in a panic. Any help really appreciated.
Olly
Don't worry about this - sorry to bother you all. It actually IS saving the file. The problem is that Linux treats it as a hidden file so you don't see it in the browser. I've added in a line to my loader:
projectLoader.setFileHidingEnabled(false);
Now you can see the files that were there (but hidden). Problem solved.
Olly
Hi ,
Please try to add this code to u'r prg.
private void writeFile(String s, String s1)
throws IOException
{
Object obj = null;
FileWriter filewriter = null;
BufferedWriter bufferedwriter = null;
if(sfmsDebug)
System.out.println("Before Writing Received Messages To a File.");
String s2 = System.getProperty("file.separator");
if(System.getProperty("os.name").toUpperCase().indexOf("WIN") !=
-1)
{
File file = new File("c:" + s2 + s1);
boolean flag = file.createNewFile();
filewriter = new FileWriter("c:" + s2 + s1, true);
bufferedwriter = new BufferedWriter(filewriter);
} else
{
File file1 = new File("/home/usr2/barcwas1" + s2 + s1);
boolean flag1 = file1.createNewFile();
filewriter = new FileWriter("/home/usr2/barcwas1" + s2 + s1, true);
bufferedwriter = new BufferedWriter(filewriter);
}
bufferedwriter.write(s, 0, s.length());
bufferedwriter.write("\r\n");
bufferedwriter.close();
filewriter.close();
if(sfmsDebug)
System.out.println("After Writing Received Messages To a File.");
}