2015-04-01 128 views
0

我想將文件從data/data/mypackage複製到/mnt/sdcard,但是當我應用命令行時,什麼也沒有發生。我的手機是植根和我有滲透,使這個command.I有數組列表,並把我所有的命令這個數組內得到的所有命令「getCommandsToExecute()」方法後,並運用我所有的命令:如何在Android中通過命令行復制文件?

public final boolean execute() { 
     boolean retval = false; 

     try { 
      ArrayList<String> commands = getCommandsToExecute(); 
      if (null != commands && commands.size() > 0) { 
       Process suProcess = Runtime.getRuntime().exec("su"); 

       DataOutputStream os = new DataOutputStream(
         suProcess.getOutputStream()); 

       // Execute commands that require root access 
       for (String currCommand : commands) { 
        os.writeBytes(currCommand + "\n"); 
        os.flush(); 
       } 

       os.writeBytes("exit\n"); 
       os.flush(); 

       try { 
        int suProcessRetval = suProcess.waitFor(); 
        if (255 != suProcessRetval) { 
         // Root access granted 
         retval = true; 
        } else { 
         // Root access denied 
         retval = false; 
        } 
       } catch (Exception ex) { 
        Log.e("ROOT", "Error executing root action", ex); 
       } 
      } 
     } catch (IOException ex) { 
      Log.w("ROOT", "Can't get root access", ex); 
     } catch (SecurityException ex) { 
      Log.w("ROOT", "Can't get root access", ex); 
     } catch (Exception ex) { 
      Log.w("ROOT", "Error executing internal operation", ex); 
     } 

     return retval; 
    } 

我的數組列表有這個命令:

ArrayList<String> hi= new ArrayList<String>(); 
hi.add("shell cp /data/data/com.askfm/databases /mnt/sdcard"); 

回答

1

你必須使用cat src >dest

有在外面的框在Android沒有cp命令。有像BusyBox這樣的工具(herethere),但它們必須單獨安裝。