Created
April 23, 2011 14:22
-
-
Save Eugeny/938641 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Writer w = SUFS.writeFile("/data/tempfile"); | |
try { | |
w.stream.writeChars("A\nB\nC\n"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
w.finish(); | |
public final class SUFS { | |
... | |
public static Writer writeFile(String file) { | |
try { | |
Process p = Runtime.getRuntime().exec("su"); | |
DataOutputStream sw = new DataOutputStream(p.getOutputStream()); | |
sw.writeBytes("tee " + file + "\nexit\n"); | |
sw.flush(); | |
Writer w = new Writer(); | |
w.proc = p; | |
w.stream = sw; | |
return w; | |
} catch (Throwable t) { | |
t.printStackTrace(); | |
} | |
return null; | |
} | |
public static class Writer { | |
public DataOutputStream stream; | |
private Process proc; | |
public void finish() { | |
try { | |
stream.close(); | |
proc.waitFor(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment