【发布时间】: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