Question

I am trying to return my project's file path to then create a file in said path. I successfully created the file in the path but I used the static path to my project rather than resolving it programatically like I need to do.

Using the docs i've tried creating my file:

    Path path = Paths.get("C:\\folder\\folder\\folder\\folder\\folder\\report\\");
    String filePath = path.toString() + "fileName.pdf";
    createFile(filePath, data, moreData);

Question:

What if someone else uses a D: drive or other? How do I resolve the report folder if that is the case?

Was it helpful?

Solution

Use a relative path to the file, rather than an absolute path.

Path path = Paths.get("reports/fileName.pdf");
String filePath = path.toString() + "fileName.pdf";
createFile(filePath, data, moreData);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top