为什么它似乎无休止地停止,当执行java代码“BufferedReader readLine()”时

时间:2013-11-16 08:49:59

标签: java android adb

我创建了一个java应用程序项目。它可以使用adb order将一个文件夹中的指定文件推送到android的sdcard。但是,我发现当它在BufferedReader.It中执行readLine方法时会被阻塞,“System.out” .println(“runCmd :: inBr toString ::”+ inBr.readLine());“代码导出没有。如果它包含更多文件,那么当推送一个文件而不是文件夹时它就可以了。   需要帮助:我该怎么做,它会在执行代码“System.out.println(”结果是::“+ lineStr)时不断导出结果;”

`   public static int runCmd(String pcmd) {
    System.out.println(pcmd.toString());
    Runtime run = Runtime.getRuntime();
    try {
        Process process = run.exec("cmd.exe /c " + pcmd.toString());
        BufferedInputStream in = new BufferedInputStream(
                process.getInputStream());
        BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
        System.out.println("runCmd::inBr toString::"+inBr.readLine());
        String lineStr;
        while ((lineStr = inBr.readLine()) != null) {
            System.out.println("the result is ::"+lineStr);
        }
        System.out.println("(lineStr = inBr.readLine()) != null---222--::"+lineStr);
        if (process.waitFor() != 0) {
            if (process.exitValue() == 1) {
                System.err.println("failed !");
                return RUN_CMD_FAILED_OTHER_REASON;
            }
        }
        inBr.close();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
        return RUN_CMD_FAILED_OTHER_REASON;
    }
    return RUN_CMD_SUCCESSFUL;
}

public static void main(String[] args){
    runCmd("adb push D:\\syncTool\\toMobileResPhoto"+ " " + "/mnt/sdcard/syncTool/toMobileResPhoto");
}

cmd shell中的结果是:C:\Users\Administrator>adb push D:\syncTool\toMobileResPhoto /mnt/sdcard/syncToo l/toMobileResPhoto push: D:\syncTool\toMobileResPhoto/kanhu_20_1384314535500.jpg -> /mnt/sdcard/syn cTool/toMobileResPhoto/kanhu_20_1384314535500.jpg push: D:\syncTool\toMobileResPhoto/gz_21_13843234984063.jpg -> /mnt/sdcard/syncT ool/toMobileResPhoto/gz_21_13843234984063.jpg push: D:\syncTool\toMobileResPhoto/gz_21_13843234984062.jpg -> /mnt/sdcard/syncT ool/toMobileResPhoto/gz_21_13843234984062.jpg push: D:\syncTool\toMobileResPhoto/gz_21_13843234984061.jpg -> /mnt/sdcard/syncT ool/toMobileResPhoto/gz_21_13843234984061.jpg push: D:\syncTool\toMobileResPhoto/bgz_20_13844854120623.jpg -> /mnt/sdcard/sync Tool/toMobileResPhoto/bgz_20_13844854120623.jpg push: D:\syncTool\toMobileResPhoto/bgz_20_13844854120622.jpg -> /mnt/sdcard/sync Tool/toMobileResPhoto/bgz_20_13844854120622.jpg push: D:\syncTool\toMobileResPhoto/bgz_20_13844854120461.jpg -> /mnt/sdcard/sync Tool/toMobileResPhoto/bgz_20_13844854120461.jpg 7 files pushed. 0 files skipped. 1469 KB/s (346069 bytes in 0.230s)

0 个答案:

没有答案