0

絶対パスが/Users/ivan/test.txtのファイルがあります

String absolutePath = file.getAbsolutePath();

ただし、フルパスが必要です:/Volumes/Macintosh HD / Users / ivan / test.txt("/"は"Macintosh HD"のエイリアスです)。

getCanonicalPathとFileSystemViewを使用してみましたが、常に同じパスを取得します。

4

3 に答える 3

1

Aliases.hファイルを見てください。具体的には、関数FSIsAliasFile()と関数のFSResolveAliasファミリ (おそらくFSResolveAlias()または) を調べる必要がありFSResolveAliasFile()ます。

私はこれを自分で試したことはありませんが、あなたが求めているものをあなたに与えるべきもののように見えます.

于 2012-05-11T11:42:04.510 に答える
0

純粋なJavaでそのパスを取得する方法はないと思います。ネイティブ共有オブジェクトを作成する必要があります。

Java-7 とFileSystemにいくつかの改善があるかもしれません

于 2012-05-11T11:45:30.170 に答える
0

最後に、Runtime を使用して実行しました (ボリューム フォルダー内の "/" エイリアスの実名フォルダーのみが必要でした:

...
// ls -al command lists the files and the alias
proc = Runtime.getRuntime().exec("ls -al /Volumes");

BufferedReader stdInput = new BufferedReader(new 
InputStreamReader(proc.getInputStream()));

String line;
// match the name between the time and the arrow
Pattern myPatter = Pattern.compile("[0-9]+:[0-9]+ (.*?) -> " + "/");
Matcher matcher;
while ((line = stdInput.readLine()) != null) {
        if (line.indexOf(" -> ") != -1){
            // get the real volume name                    
            matcher = myPatter.matcher(line);
            if (matcher.find())
                return matcher.group(1);                     
        }                    
}
...      
于 2012-05-12T20:37:44.070 に答える