美文网首页Android
Android read file with space in

Android read file with space in

作者: JaedenKil | 来源:发表于2019-06-10 17:03 被阅读0次

    In an instrument test, there is the need to read a file from folder /data/data/com.somePkg.xxx/files/My Baselines/20180111.ptm.

    The usual way File file = new File(String path) won't work, since the target file is in a private package folder, it is not accessible, so have to use cat.

    UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    String res = mDevice.executeShellCommand("cat /data/data/com.somePkg.xxx/files/My Baselines/20180111.ptm")
    

    But there is a terrible issue with the space in the dict name "My Baselines", using "\ " won't work.
    In the end, have to use find command to get the file path and cat it directly:

    String pkgFolder = "/data/data/com.somePkg.xxx/"
    String cmd = "su 0 find " + pkgFolder + " -name *ptm -exec cat {} + ";
    String res = mDevice.executeShellCommand(cmd);
    

    And it works!

    相关文章

      网友评论

        本文标题:Android read file with space in

        本文链接:https://www.haomeiwen.com/subject/asftfctx.html