Skip to main content

Problems with / and \ compatibility

2 replies [Last post]
Joined: 2005-04-21


I have to load some files. I read the path names from an XML file, and lets say I have a string like "data\images\myimage.png". If I load this with ImageIO it will work ok under Windows, but it won't work under Linux, probably because of the usage of the \ slash instead of the /

So is there a way to universally load file names no matter which slashes are used? Or if not, then how can I find out which slash is used by the current system? Then in case the / is sued I could go through the string and replace where necessary...

Waiting for your reply,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-10

It's probably best to replace all "/" and "\" characters with File.separator in your pathnames. String.replace() should accomplish that easily enough.

Joined: 2004-06-21

/ should work, even in windows platform

To know the specific path separator for your platform, try:
- System.getProperty("file.separator");
- File.pathSeparator
- File.pathSeparatorChar
- File.separator
- File.separatorChar

See javadoc for File class for more info