Android Question [solved]How judge same file

Discussion in 'Android Questions' started by Maodge, Jun 27, 2018.

  1. Maodge

    Maodge Member Licensed User

    when i use file explorer lib (, i get diffrent path for the same selected file.
    for example : /mnt/sdcard/1.txt , /sdcard/1.txt, /storage/sdcard/1.txt ...
    above all is the same file.
    so i can't using compare filename equals and filepath equals to judge the file is same with the exists file.

    then i searching web.and find some java code. these code seems can solved this problem.
    public static boolean isSymlink(File file) throws IOException 
    if (file == null)           
            throw new NullPointerException(
    "File must not be null");       
    File canon;       
    if (file.getParent() == null
            canon = 
            File canonDir = file.getParentFile().getCanonicalFile();           
            canon = new File(canonDir, file.getName());       
        return !canon.getCanonicalFile().equals(file.getAbsoluteFile());   
    my question, how can i using these code in b4a? Thanks
  2. Erel

    Erel Administrator Staff Member Licensed User

    Doesn't sound like the correct solution. Why does it matter that there are multiple paths to the same file?

    You can get the canonical path with:
    Dim jo As JavaObject
    Dim path As String = jo.RunMethod("getCanonicalPath"Null))
  3. Maodge

    Maodge Member Licensed User

    Thank you very much,I' m learning the use of the javaobject and reflection libraries. this code works very well in my program, It is very helpful to me
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice