使用Rsync在两个android设备之间同步文件


  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成功。你能给我一些建议吗?

我已经解决了

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) {// 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();
            }
}

最新更新