How can I make OS X recognize drive letters?

I know. Heresy. But I am attached. I have many configuration files that use absolute path names, which creates incompatibility between OS X and Windows. If I can get OS X (which makes bets more flexible of the two) to recognize Q: /foo/bar/bim.properties as a valid absolute file name, this will save me several days of work on the trace stack and configuration files.

In the end, I need this bit of Java test code to print “SUCCESS!”. at startup:

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!");
        }
    }
}

Does anyone know how to do this?

UPDATE: Thanks for all the reviews, everyone. Now it is obvious to me that I should have been more clear in my question.

, , , . (, , , , , .)

, . : , .

+3
7

, java.io.File, , , - .
, ( ) , .

+1

,, , . .

- , , , , ... .

Q: / /.

$ cd /
$ ln -s / Q:
$ ln -s / S:

, sudo. , , chdir /.

, Q: S: Finder,

$ /Developer/Tools/SetFile -P -a V Q:
$ /Developer/Tools/SetFile -P -a V S:

Finder .

+3

: №. : Java System.getProperties(XXX). , os.name.
S:, , Windows, .
: , , OSX .

public class WhichOS
{
    public static void main(final String[] args)
    {
        System.out.format("System.getProperty(\"os.name\") = %s\n", System.getProperty("os.name"));
        System.out.format("System.getProperty(\"os.arch\") = %s\n", System.getProperty("os.arch"));
        System.out.format("System.getProperty(\"os.version\") = %s\n", System.getProperty("os.version"));
    }
}

iMac:

System.getProperty("os.name") = Mac OS X
System.getProperty("os.arch") = x86_64
System.getProperty("os.version") = 10.6.4
+3

, ?

.

, , Windows, :

- :

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:
}

+2

java.io.File - rt.jar.

, - bsd- OpenJDK , , . script, java, .

PS. ! .

+2

- - : Windows, (.. - ), . , , , .

+1

, , :

java.io java.io.File, , . , "/Volumes/" , System.err, .

"" "", , :

  • /Volumes/S:
  • /Volumes/Q:

. , , .

: java.io.File , "S:/bling.properties", . OS X, "/Volumes/" /Volumes/S:/bling.properties, , .

Yes, that’s terrible, damn it. But today he is doing his job.

+1
source

Source: https://habr.com/ru/post/1754857/


All Articles