1 Open sudo terminal
Runtime.exec ("Echo Your root password | Sudo-s your order ");
2 creating different operating system directories
File fp = new file (Lastsfolderpath);
Create a table of contents
if (!fp.exists ()) {
Create a directory if the Fp.mkdirs ()//directory does not exist.
if ( -1!= system.getproperties (). GetProperty ("Os.name")
. toLowerCase (). IndexOf ("Windows")) {
1 Windows OS: Grant read-write access to file paths via IO file class
if (!fp.canread ()) {
Fp.setreadable (TRUE);
}
if (!fp.canwrite ()) {
Fp.setwritable (TRUE);
}
if (!fp.canexecute ()) {
Fp.setexecutable (TRUE);
}
} else {
1 2 Other operating systems
: Runtime.getruntime (). EXEC () Execute command to grant read and write access to file paths
String filepath = Lastsfolderpath;
String command = "chmod-r 755" + filepath;
@SuppressWarnings ("unused")
Runtime Runtime = Runtime.getruntime ();
try {
@SuppressWarnings ("unused")
Process exec = Runtime.getruntime (). exec (command);
catch (IOException e) {
E.printstacktrace ();
}
}
}