简体   繁体   English

如何在android中获取文件的权限和属性

[英]how can I get the permissions and properties of a file in android

how can I get the permissions of files listed in eclipse DDMS for android by code.如何通过代码获取 eclipse DDMS for android 中列出的文件的权限。 And also the properties like 1).还有像1)这样的属性。 Owner and it's permission like read ,write ,execute 2).所有者及其权限,如读取、写入、执行 2)。 Group and it's permission like read ,write ,execute 3).组和它的权限,如读取、写入、执行 3)。 Permissions for others其他人的权限

Thanks in advance.提前致谢。

    ProcessBuilder processBuilder = new ProcessBuilder("ls", "-l").directory(new File(file.getParent()));// TODO CHECK IF THE FILE IS SD CARD PARENT IS NULL
  if(BuildConfig.DEBUG)Log.v(TAG, "dir:-"+processBuilder.directory());
  Process process = processBuilder.start();
  PrintWriter out = new PrintWriter(new OutputStreamWriter(process.getOutputStream()));
  BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  out.flush();
  String resultLine;
  resultLine = in.readLine();
  
  while (resultLine != null) {
      System.out.println(resultLine);
}

The result of the above code will be ,上面代码的结果将是,

  • " lrwxrwxrwx root root 2012-12-12 13:34 sdcard " " lrwxrwxrwx root root 2012-12-12 13:34 sdcard "

in this result the first 10 characters are permissions.在这个结果中,前 10 个字符是权限。 in that,在那里面,

  • 2,3,4 characters - shows read,write,execute permission of owner, 2,3,4 个字符 - 显示所有者的读、写、执行权限,

  • 5,6,7 characters - shows read,write,execute permission of group, 5,6,7 个字符 - 显示组的读、写、执行权限,

  • 8,9,10 characters - shows read,write,execute permission of others 8,9,10 个字符 - 显示其他人的读、写、执行权限

    then, owner and group are,然后,所有者和组是,

  • 11 to 19 characters - shows owner of the file, 11 到 19 个字符 - 显示文件的所有者,

  • 20 to 29 characters - shows group of the file. 20 到 29 个字符 - 显示文件组。

Try this api试试这个api

http://developer.android.com/reference/android/Manifest.permission.html http://developer.android.com/reference/android/Manifest.permission.html

ACCESS_CHECKIN_PROPERTIES :Allows read/write access to the "properties" table in the checkin database, to change values that get uploaded. ACCESS_CHECKIN_PROPERTIES :允许对签入数据库中的“属性”表进行读/写访问,以更改上传的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM