Create a file in /system directory

2019-03-04 03:42发布

问题:

I want to create a file in the /system directory. I think that directory is "protected" and the phone must be rooted to access and create to it. I used this simple code to create a file in /system but nothing is created:

File file = new File("/system", "test.prop");

How can i solve that problem? Thank you for your help.

回答1:

I can't tell how to implement the following steps but I think it's not too hard to find a solution on the net:

  • acquire root-access for your application
  • check if /system is mounted with option rw, if not, remount it so

hint: use the "adb shell" and check if the upper steps can lead to success (su && remount -o remount,rw /system && touch /system/test)

On some devices there's the unlucky chance that the internal memory is in protected mode (google S-ON / S-OFF). If this is the case for you it will not be that easy like I imagined. But even than it must be possible, since the market is installing files there. This would be the last hint, to look at the market source-code ;/



回答2:

You need to call following method on file object

file.createNewFile();

On executing this following error comes because of read-only directory

11-09 19:45:15.136: E/VideoSample(4245): java.io.IOException: open failed: EROFS 
                    (Read-only file system)
11-09 19:45:15.136: E/VideoSample(4245):    at 
                     java.io.File.createNewFile(File.java:940)