[英]How to obtain file permission using roottools
I want to obtain linux file permissions without parsing ls -l. 我想获取Linux文件权限而不解析ls -l。 Since I will be using RootTools, I see it has a Permissions class, but how should I obtain permission data of a File into that object?
由于我将使用RootTools,因此我看到它具有Permissions类,但是如何将File的许可权数据获取到该对象中?
If you can't modify source use reflection: 如果您不能修改源,请使用反射:
private Permissions RootToolsInternalMethods_getPermissions(String line)
{
try
{
RootTools rootTools = new RootTools();
Method method = rootTools.getClass().getDeclaredMethod("getInternals");
method.setAccessible(true);
RootToolsInternalMethods rootToolsInternalMethods = (RootToolsInternalMethods)method.invoke(rootTools);
return rootToolsInternalMethods.getPermissions(line);
}
catch (Exception ignore) {}
return null;
}
RootToolsInternalMethods have getPermissions(String) method, but they can only be accessed in RootTools class RootToolsInternalMethods具有getPermissions(String)方法,但只能在RootTools类中访问
From RootTools source 从RootTools来源
private static final RootToolsInternalMethods getInternals() {
if (rim == null) {
RootToolsInternalMethods.getInstance();
return rim;
} else {
return rim;
}
}
Seems like I have to modify RootTools source and get the permissions from ls -l output 好像我必须修改RootTools源并从ls -l输出获取权限
getInternals().getPermissions("ls -l output line");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.