尝试获取文件的inode,尝试使用以下代码,它适用于api> = 19(实际上api> 21 android有Os获取inode信息),但是在api< = 18命令“ls -il “不会返回任何东西。
也试过“/ 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;
}
答案 0 :(得分:0)
您可以使用 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'