Search code examples
javamacosprintwriter

PrintWriter default location


I'm trying to write to a file. The code runs without an error, but I can't find the file anywhere. Not in the execution path, desktop, home folder, root folder.

Of course I could specify absolute paths, but I'm trying to figure out what a relative path is relative to, because I've seen examples like this.

try {
    PrintWriter out = new PrintWriter ("example.txt");
    out.print("test");
    out.flush();
    out.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
}

Solution

  • The file exists is in the current application path as indicated by new File("example.txt").getAbsolutePath()