絶対パスが/Users/ivan/test.txtのファイルがあります
String absolutePath = file.getAbsolutePath();
ただし、フルパスが必要です:/Volumes/Macintosh HD / Users / ivan / test.txt("/"は"Macintosh HD"のエイリアスです)。
getCanonicalPathとFileSystemViewを使用してみましたが、常に同じパスを取得します。
Aliases.hファイルを見てください。具体的には、関数FSIsAliasFile()
と関数のFSResolveAlias
ファミリ (おそらくFSResolveAlias()
または) を調べる必要がありFSResolveAliasFile()
ます。
私はこれを自分で試したことはありませんが、あなたが求めているものをあなたに与えるべきもののように見えます.
純粋なJavaでそのパスを取得する方法はないと思います。ネイティブ共有オブジェクトを作成する必要があります。
Java-7 とFileSystemにいくつかの改善があるかもしれません
最後に、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);
}
}
...