File.getCanonicalPath()
具体用法看看文档吧,

解决方案 »

  1.   

    getCanonicalPath
    public String getCanonicalPath()
                            throws IOException
    Returns the canonical pathname string of this abstract pathname. 
    A canonical pathname is both absolute and unique. The precise definition of canonical form is system-dependent. This method first converts this pathname to absolute form if necessary, as if by invoking the getAbsolutePath() method, and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Win32 platforms). Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent file or directory also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the file or directory is created. Similarly, the canonical form of the pathname of an existing file or directory may be different from the canonical form of the same pathname after the file or directory is deleted. 
    Returns:
    The canonical pathname string denoting the same file or directory as this abstract pathname 
    Throws: 
    IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries 
    SecurityException - If a required system property value cannot be accessed.
      

  2.   

    诸位误会我的意思了。
    我的意思是要取得lnk快捷方式文件所指向的目标文件的地址;
    比如 d:\test\a.txt,创建的对应的shortcut的文件为d:\a.txt.lnk。
    如果用getCanonicalPath(),取到的还是d:\a.txt.lnk,
    而我想取到的是d:\test\a.txt这个地址。
    这个windows中shortcut文件的属性Target。
      

  3.   

    哦,Windows的好像不行了,不过 getCanonicalPath 是可以得到Linux 的 symbol link 的,
    如果你足够闲并且足够转牛角尖的话 :Phttp://www.moon-soft.com/program/FORMAT/windows/Lnk.htm自己写一个解析 lnk 文件的类吧 :P