views:

49

answers:

1

Possible Duplicate:
How can I make OS X recognize drive letters?

I know. Heresy. But I'm in a bind. I have a lot of config files that use absolute path names, which creates an incompatibility between OS X and Windows. If I can get OS X (which I'm betting is the more flexible of the two) to recognize "Q:/foo/bar/bim.properties" as a valid absolute file name, it'll save me days of work spelunking through stack traces and config files.

In the end, I need this bit of Java test code to print "SUCCESS!" when it runs:

import java.io.*;
class DriveLetterTest {
  static public void main(String... args) {
    File f = new File("S:");
    if (f.isDirectory()) {
      System.out.println("SUCCESS!");
    }
    else {
      System.out.println("FAIL!");
    }
  }
}

Anyone know how this can be done?

A: 

If you are not willing to change your config file per OS, what are they for in first place?

Every installation should have its own set of config files and use it accordingly.

But if you insist.. you just have to detect the OS version and if is not Windows, ignore the letter:

Something along the lines:

boolean isWindows = System.getProperty("os.name")
                     .toLowerCase().contains("windows"); 

String folder = "S:";
if( isWindows && folder.matches("\\w:") {
     folder = "/";
 } else if( isWindows && folder.matches("\\w:.+)) {
     folder = folder.substring(2);// ignoring the first two letters S:
 }

You get the idea

OscarRyz
Is there not a Java file path class that can do that better?
Schwern