100% of the Java work I do is on Android. When constructing file paths, I always make sure to use File.pathSeparator File.separatorChar instead of “/”.
What determines the value of File.pathSeperator? Are there any Android devices where File.pathSeparator File.separatorChar will not be “/” ?
According to the source code of File.java,
pathSeparatoris pulled from the charSystem.getProperty("path.separator", ":").charAt(0).separator, on the other hand, comes fromSystem.getProperty("file.separator", "/").charAt(0).Because Android is Linux-based, it should always be
/. However, I have seen glitches where:has appeared instead (Motorola Droid; see bug report), by using the default value above.When I code, I always use
/… to be honest, I don’t think it’s necessary to reference theFileclass (this would mostly be for non-Android work). It’s just best to stick to/, I think.Additionally, according to this answer (pertains to Java, not just Android),
/can safely be used on all Java platforms, and it will figure out what it needs to use internally.