0

I'm wondering, what is the best way to get a File in Java regardless of the OS?

File pdfSource = new File(directory.toString() + File.separator + "report_" + uuid + ".pdf");

or

File pdfSource2 = Paths.get(directory.toString(), "report_" + uuid + ".pdf").toFile();

Thanks! :)

Xxtreem
  • 173
  • 1
  • 13

1 Answers1

0

I think they are equals. But the second one based on Paths is much simpler to read.

Paths is more recent API introduce with Java 7. So it can cause an issue for people using a very old version of Java.

mcoolive
  • 3,805
  • 1
  • 27
  • 32