2014-03-27 54 views
0
try { 
     Process process = Runtime.getRuntime().exec("/system/xbin/su -c sh"); 
     DataOutputStream os = new DataOutputStream(process.getOutputStream()); 


     os.writeBytes("/system/xbin/rsync -avzru /data/shareData/ 192.168.84.111:/data/shareData/"); 
     String output=new String(); 



     os.flush(); 
} catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     Log.i("rsync",""+e.getMessage()); 
} 

但沒有給出任何日誌輸出,也沒有rsync的成功。你能給我一些建議嗎?使用rsync的兩個android設備之間的rsync文件

回答

0

我有解決

public static void startRsync() { 


    Thread thread = new Thread() { 
     @Override 
     public void run() { 
      try { 

        Process process = Runtime.getRuntime().exec("su -c sh"); 
        OutputStream os = process.getOutputStream(); 

        writeLine(os, "/system/xbin/rsync --daemon --config=/etc/rsyncd/rsyncd.conf"); 
        os.flush(); 
        //process.waitFor(); 


      } 
      catch (IOException e) { 
       e.printStackTrace(); 
      } 

//趕上(InterruptedException的發送){// e.printStackTrace(); //} } }; thread.start();

// sleep to give some time to statusRsync to detect process 
      try{ 
       Thread.currentThread().sleep(2000);//sleep for 2000 ms 
      } 
      catch(InterruptedException e){ 
       e.printStackTrace(); 
      } 

}