【问题标题】:how to get inode from android <19如何从android <19获取inode
【发布时间】:2017-06-26 12:47:48
【问题描述】:

试图获取文件的inode,尝试了以下代码它适用于api> = 19(实际上api> 21 android有Os来获取inode信息),但在api

也试过“/system/bin/ls -il”,也没有返回。

ls -il 在 api >=19 上返回“114993 -rw-rw---- u0_a59 u0_a59 9801728 2017-02-08 13:08 thefileName.ext”。

不确定这是否是获取 inode 信息的可靠方法。

public static String getIndoeFromPath(String path){
    String inode = "";
    String cmd = ("ls -il " + path);

    BufferedReader reader = null;
    try {
        Process process = Runtime.getRuntime().exec(cmd);
        reader = new BufferedReader(
                new InputStreamReader(process.getInputStream()));
        int read;
        char[] buffer = new char[4096];
        StringBuffer output = new StringBuffer();
        while ((read = reader.read(buffer)) > 0) {
            output.append(buffer, 0, read);
        }
        reader.close();            
        process.waitFor();

        String ret = output.toString();

        Log.d(TAG, "getIndoeFromPath(), output.toString():"+
 output.toString()+", ret = output.toString();:"+ret); /<=== it has empty in the string

        if (!TextUtils.isEmpty(ret)) {
            ret = ret.trim();
            String[] splitArr = ret.split("\\s+");
            if (splitArr.length>0) {
                inode = splitArr[0];
            }
        }            
    } catch(Exception e) {} 
    finally {
       if (reader != null) {
           try {
               reader.close();
           } catch (IOException e) {}
       }
    }
    return inode;
}

【问题讨论】:

    标签: android runtime.exec inode


    【解决方案1】:

    你可以使用stat命令

    'stat README.txt
    File: README.txt
    Size: 480      Blocks: 8       IO Blocks: 512 regular file
    Device: fd09h/64777d     Inode: 269424   Links: 1
    Access: (0777/-rwxrwxrwx)       Uid: ( 2000/   shell)   Gid: ( 2000/   shell)
    Access: 2017-11-01 12:55:56.000000000 +0200
    Modify: 2017-11-01 12:55:56.000000000 +0200
    Change: 2021-01-17 15:55:19.367560281 +0200'
    

    【讨论】:

      猜你喜欢
      • 2011-12-20
      • 2023-03-22
      • 1970-01-01
      • 2015-04-15
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 2011-11-27
      相关资源
      最近更新 更多