I’m trying to fetch a PDF on my desktop and output it within my Java program. I am getting an error when I run the program which is :
java.lang.IllegalArgumentException: The file: CVliamdocherty.pdf
doesn’t exist.
import java.util.Scanner; //taking input from user
import java.io.File;
import java.awt.Desktop;
//Help section method
public static void helpsection() {
try {
Desktop.getDesktop().open(new File("CVliamdocherty.pdf"));
} catch(Exception e) {
System.out.println(e);
}
}
The file does exist with the file correct name and it is located on the desktop.
The problem is the file path. I’m on Mac what would the file path be for this file located on the desktop? I did try “”./desktop/CVliamdocherty.pdf" but it didn’t work.