TShopping

 找回密碼
 註冊
搜索
查看: 526|回復: 0

[教學] Android: Writing file on system partition and use chmod or chown

[複製鏈接]
發表於 2013-10-19 00:15:59 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 
  1. FileOutputStream out = openFileOutput("myfile.test", MODE_WORLD_READABLE);
  2. File f = getFileStreamPath("myfile.test");
  3. writeDataToOutputStream(out);
  4. out.close();
  5. String filename = f.getAbsolutePath();
  6. Runtime r = Runtime.getRuntime();
  7. Process suProcess = r.exec("su");
  8. DataOutputStream dos = new DataOutputStream(suProcess.getOutputStream());
  9. dos.writeBytes("chown 0.0 " + filename + "\n");
  10. dos.flush();
  11. dos.writeBytes("chmod 644 " + filename + "\n");
  12. dos.flush();
  13. dos.writeBytes("mv " + filename + " /system/myfile.test\n");
  14. dos.flush();
複製代碼

The only thing left (not include din the code above) is to make /system writable. May be one additional command like mount -o rw,remount /system is sufficient - will test that.

在改變檔案權限時,請先r.exec("su");
就能正常執行下面語句

 

臉書網友討論
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2016-12-3 09:56 , Processed in 0.052324 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表