Is there any way to have a code that opens a PDF file in Java application in a platform independant way? I mean using a batch file in Windows could do that. Is there any oth
3-rd party applications can not access src dir in your application, in case, when your app assemble in jar archive. You should place your file separately from src.
Of course, java find icons, because it's java API. You can access any resources in src folder through follow methods:
URL url = getClass().getResource("/path/in/src");
File file = new File(url.toURI());
I am currently using the below:
if (Desktop.isDesktopSupported()) {
try {
URL url = getClass().getResource("/pdf/XXXX.pdf");
File myFile = new File(url.toURI());
Desktop.getDesktop().open(myFile);
} catch (IOException | URISyntaxException ex) {
// no application registered for PDFs
}
}