As the subject suggests, I'm having a problem getting my head around how to use paths to files in java programs. I am using a windows machine so a typical path to a file would be something like C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg. The following is a basic program that uses a file called Sunset.jpg.
This will only work if Sunset.jpg is in the same folder as the program source file. Sure, I can move or copy jpg files but if I just wanted to have them in one basic image folder on my computer while Java programs access them ,and not move them or have multiple copies, I think I should be able to reference them using a path. But...
...doesn't work. It just tells me that the line's full of illegal escape characters (caused by the use of the backslashes, no doubt). I'm sure my problem involves more than just the improper use of backslashes. I've tried doing several things different but to no avail. I don't know why but the more I've read regarding paths the more confused I've become. Then there're URLs...Don't get me started on them.
Could anyone point me toward a clear explanation of how to use paths in Java? I don't have any problem moving through paths on my computer normally but when it comes to doing it in Java, I'm off the path and lost in the woods.
Check a How to Use Icons, it should provide a good background on the topic you're having issue with.
Also, backslash (\) sign is an escape character in Java. In order to have it as part of the string (absolute path, or wherever you need it) you need to put two successive backslash signs (\\).
The quieter you are, the more you are able to hear.
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.