在java中读取shell脚本输出(wget)

时间:2014-01-21 20:03:04

标签: java shell wget

我正在尝试为wget编写图形界面。 我可以在java中运行shell脚本并读取脚本的输出,但是在wget的情况下,以下代码将不起作用。

Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec("wget someAddress");
        InputStream output = proc.getInputStream();
        int nextByte = output.read();
        while(nextByte != -1){
            System.out.print((char)nextByte);
            nextByte = output.read();
        }

那么我该怎么办才能获得下载的费用呢?

提前致谢

1 个答案:

答案 0 :(得分:2)

如果您需要从Java中坚持Wget,您可能需要检查磁盘上的下载文件,并从不断增加的大小中确定您的百分比。