Get the directory from a file path in java (android)

前端 未结 4 1631
无人及你
无人及你 2020-12-25 12:16

Is there a function to get the directory part of a file path?

so from

String a=\"/root/sdcard/Pictures/img0001.jpg\";
4条回答
  •  孤城傲影
    2020-12-25 13:02

    I have got solution on this after 4 days, Please note following points while giving path to File class in Android(Java):

    1. Use path for internal storage String path="/storage/sdcard0/myfile.txt";
    2. path="/storage/sdcard1/myfile.txt";
    3. mention permissions in Manifest file.

    4. First check file length for confirmation.
    5. Check paths in ES File Explorer regarding sdcard0 & sdcard1 is this same or else......

    e.g.

    File file=new File(path);
    long=file.length();//in Bytes
    

提交回复
热议问题