方法一;
Runtime runtime = Runtime.getRuntime();
runtime.exec("chmod 777 "+"<指定路径>");
注意命令chmod 777 后面要带上空格,否则会无效
runtime.exec("chmod 777 "+"<指定路径>");
注意命令chmod 777 后面要带上空格,否则会无效
我在super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);两句后面加上了 try { Runtime.getRuntime().exec("chmod 644 " + "/storage/sdcard0/ccfile/tttro.apk"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 路径是绝对存在的,但是为什么不成功呢?
最好先进到当前路径再执行
Runtime.getRuntime().exec("cd " + "/storage/"); Runtime.getRuntime().exec("chmod 777 " + "./"); 也就是说你的权限可能要一级一级目录的设置 因为如果你的父目录无权限的话,那么直接设置子目录权限 也是没有用的