To use a Linux Command, you must first obtain the root user. Remember to add busybox when executing the command. Generally, the basic method of Java I/O cannot place the file into a USB file. You can use Linux commands.
Processbuilder Pb = new processbuilder ("/system/bin/sh ");
// Java. Lang. processbuilder: Creates operating system processes.
PB. Directory (new file ("/"); // you can specify the current directory of the shell.
Try {
Process proc = Pb. Start ();
// Obtain the input stream, which can be used to obtain the shell output.
Bufferedreader in = new bufferedreader (New inputstreamreader (Proc. getinputstream ()));
Bufferedreader err = new bufferedreader (New inputstreamreader (Proc. geterrorstream ()));
// Obtain the output stream, which can be used to send commands to shell.
Printwriter out = new printwriter (New bufferedwriter (New outputstreamwriter (Proc
. Getoutputstream (), true );
Out. println ("PWD ");
Out. println ("su root"); // when this sentence is executed, a dialog box is displayed (the following program requires the highest permission to be granted...), asking the user to confirm.
Out. println ("CD/data/Data"); // This directory must have the root permission in the system for access.
Out. println ("ls-L"); // if this command can list the data file storage directory of the currently installed APK, it means that we have the root permission.
Out. println ("exit ");
// Proc. waitfor ();
String line;
While (line = in. Readline ())! = NULL ){
System. Out. println (line); // print the output result.
}
While (line = err. Readline ())! = NULL ){
System. Out. println (line); // print the error output
}
In. Close ();
Out. Close ();
Proc. Destroy ();
} Catch (exception e ){
System. Out. println ("exception:" + E );
}
File superuser = new file ("/system/bin/superuser ");
If (superuser. exists ())
{
// Return device to original state
Process = runtime.getruntime(cmd.exe C ("superuser ");
Dataoutputstream OS = new dataoutputstream (process. getoutputstream ());
OS. writebytes ("Mount-oremount, RW/dev/block/mtdblock3/System \ n ");
OS. writebytes ("busybox CP/system/bin/superuser/system/bin/su \ n ");
OS. writebytes ("busybox chown 0: 0/system/bin/su \ n ");
OS. writebytes ("chmod 4755/system/bin/su \ n ");
OS. writebytes ("RM/system/bin/superuser \ n ");
OS. writebytes ("Exit \ n ");
OS. Flush ();
}