Path to file on a Mac: FileNotFoundException
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?
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");
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.
精彩评论