Reputation: 33771
I'm working on a mac and I'm trying to specify the path to a file on my desktop.
I just did it like this: File file = new File("/users/desktop/sample.json");
When I tried running it I got a FileNotFoundException.
How do I correctly specify the path?
Upvotes: 8
Views: 61388
Reputation: 724402
Since you're looking for your desktop folder in particular, and not the root folder of a user with the name "desktop", you need to add your username after the Users folder. For example:
File file = new File("/Users/LuxuryMode/Desktop/sample.json");
Upvotes: 22
Reputation: 57
To get to know your correct path to be given, drag n drop your file in Mac terminal
, which would give you the path of the file which would look like
ex:/Users/Smith/Desktop/PI/ABApBASICS.docx
All you got to do is paste this code in Eclipse but mind you blackslash would throw you an error: invalid escape sequence
solution:
ex://Users//Harish//Desktop//PI//ABApBASICS.docx
I was able to read the file without error inputting above path.
Upvotes: 4