The counter question I get when I see this is: “Why do you want to hardcode the path in your application?”
Even if it were just for example, and you intend to load the path from the properties file or something else, I still think that you are mistaken here.
First of all, you will want to avoid absolute paths such as the plague. Relative paths like approx. You can use slash characters ('/') in hard path encodings, they will work on both Windows and Linux / Mac. Mostly all platforms.
Secondly, why use the paths at all? This is the internet age. Use URL! file: The URL will do the same as the file paths, but using the URL, the application can also accept resources from other sources, such as websites and FTP.
Third, avoid the File class. If you come up with a good way to do this, you are completely made of wood. Use the URL along with getResource and getResourceAsStream, and your application will work regardless of platform and across network boundaries over the Internet.
Stijn de witt
source share