What would the file path be?

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.

Can you get the absolute path somehow?
https://www.roseindia.net/java/beginners/GetAbsolutePath.shtml

When I run the code there is an error, thanks for the post.

Would you like to share the error? :face_with_raised_eyebrow:

java.lang.ArrayIndexOutOfBoundsException: 0
at GetAbsolutePath.main(GetAbsolutePath.java:5)
java.lang.ArrayIndexOutOfBoundsException: 0
at GetAbsolutePath.main(GetAbsolutePath.java:5)

What about this method for getting the desktop abs path:

Just open you desktop and right click on the file you want and view the properties. Copy and paste the location