Short. I copy the file, set the rights, open for reading

Java.Lang.Runtime.GetRuntime().Exec(new string[] { "su", "-c", "cp", fromFile.AbsolutePath , toFile.AbsolutePath }); Java.Lang.Runtime.GetRuntime().Exec(new string[] { "su", "-c", "chmod", "666", toFile.AbsolutePath }); using (FileInputStream fr = new FileInputStream(toFile)) { ... } 

Fails with an error on FileInputStream

/dir1/dir2/file.blablabla: open failed: EACCES (Premission denied)

Initially, the file has read permissions only for su but in the file manager I look after the execution of commands at the file toFile right 666.

What could be the snag?

    1 answer 1

    It turned out to pull the data from the problem file.

    unreadFile - Problem file

    fullTempName - Stretched data

     using (Java.Lang.Process p = Java.Lang.Runtime.GetRuntime().Exec("su")) { using (DataOutputStream os = new DataOutputStream(p.OutputStream)) { os.WriteBytes("cat \"" + unreadFile + "\"\n"); os.Flush(); os.Close(); using (DataInputStream ins = new DataInputStream(p.InputStream)) { byte[] buff = new byte[4096]; int count = ins.Read(buff, 0, 4096); using (System.IO.FileStream fs = System.IO.File.OpenWrite(fullTempName)) { while (count > 0) { fs.Write(buff, 0, count); count = ins.Read(buff, 0, 4096); } fs.Close(); } } } 

    If there are other ways, please inform ... Thank you.