I want to obtain linux file permissions without parsing 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?
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
From RootTools source
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
getInternals().getPermissions("ls -l output line");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.