Search code examples
javasrcioexceptionfileoutputstream

src/ file path not found


I want to save a serializable object into the src/ folder.

File file = new File("src/test.ser");
file.createNewFile();
fout = new FileOutputStream(file);
oos = new ObjectOutputStream(fout);
oos.writeObject(object);

However, The system cannot find the path specified error messege pops up. The method works if I use an absolute file path though.

If this is in any way relevant, I've added another project into the build path.


Solution

  • Use ./ before src.

    File file = new File("./src/test.ser");
    file.createNewFile();
    fout = new FileOutputStream(file);
    oos = new ObjectOutputStream(fout);
    oos.writeObject(object);