2012-05-11 16 views
0

でライオンに(別名なし)完全なファイルパスを取得し、私は絶対パスとファイルがあります:/Users/ivan/test.txtJavaの

String absolutePath = file.getAbsolutePath(); 

をしかし、私は完全なパスが必要になります。/ボリューム/ Macintosh HD/Users/ivan/test.txt(「/」は「Macintosh HD」のエイリアスです)。

私はすでにgetCanonicalPathとFileSystemViewを使ってみましたが、私はいつも同じパスを取得しています。

+0

正確に '/ Volumes/Macintosh HD'が必要なのですか? –

+0

@ThomasMuellerなぜならファイルの容量を知る必要があるからです。 – Ivan

答えて

0

がある(私は唯一のボリュームフォルダ内の「/」エイリアスの実名フォルダ必要:

... 
// 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);      
     }      
} 
...  
1

Aliases.hファイルをご覧ください。具体的には、関数FSIsAliasFile()FSResolveAliasファミリの関数を参照する場合は、FSResolveAlias()またはFSResolveAliasFile()となります。

私はこれを試したことはありませんが、あなたの後ろのものを与えるはずのもののように見えます。

0

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

Mayeは最後に、私はそれがランタイムを使用したJavaの-7といくつかのimporvementsとFileSystem