Write file with root access in Android Java?


This Content is from Stack Overflow. Question asked by Rick Wilting

Is it possible to write to places like /, /system/, etc. Just paths you wouldn’t normally be able to without root.

I have Root Access on my device, so rooting is no problem.

How would I be able to make this script ask for su permissions and write to any locations with no problems like access denied?

            URL website = new URL("http://myurl.com/index.html");
            ReadableByteChannel rbc = Channels.newChannel(website.openStream());
            FileOutputStream fos = new FileOutputStream(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM));
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?