Reputation: 21
So, here is the code that I have:
try
{
PlayerSave save = new PlayerSave(this);
save.playerLooks = look;
File test = new File("C:/cache/" + playerName + ".tmp");
test.createNewFile();
FileOutputStream f_out = new
FileOutputStream("C:/cache/" + playerName + ".tmp");
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject (save);
obj_out.close();
f_out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Upon execution, I get the following error:
java.io.FileNotFoundException: C:\cache\Bobdole.tmp (The system cannot find the path specified)
I have also tried using this code:
try
{
PlayerSave save = new PlayerSave(this);
save.playerLooks = look;
// File test = new File("C:/cache/" + playerName + ".tmp");
// test.createNewFile();
FileOutputStream f_out = new
FileOutputStream("C:/cache/" + playerName + ".tmp");
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject (save);
obj_out.close();
f_out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
However, it produces the same error. I am confused as to why this is not working, as everything seems to be right. If you guys can figure out the problem that would be so helpful. Thanks!!
Upvotes: 1
Views: 238
Reputation: 63482
That's telling you that the directory C:\cache
does not exist. The directory must exist in order for you to be able to write files to it. You can either create it manually, or with something like:
File directory = new File("C:\\cache");
directory.mkdir();
Upvotes: 2