2 qq 21108099 qq_21108099 于 2015.06.12 09:00 提问

bufferedreader有值但是readline没值怎么回事啊 5C

源代码

 Process pro;
        try {
            //用Java编写应用时,有时需要在程序中调用另一个现成的可执行程序或系统命令,这时可以通过组合使用Java提供的Runtime类和Process类的方法实现。
            pro = Runtime.getRuntime().exec(commandBuidler.toString());
            System.out.println(pro==null);
            System.out.println(pro.getInputStream()+"#");
            BufferedReader buffer=new BufferedReader(new InputStreamReader(pro.getInputStream()));
            System.out.println(buffer+"%");
            System.out.println(buffer==null);
            String str = buffer.readLine(); 
            System.out.println(buffer.readLine()+"&");
            System.out.println(buffer.readLine()==null);
            System.out.println(str+"*");
            while(null!=str){ 
                str = buffer.readLine(); 
                if(null==str){ 
                  pro.destroy(); 
                } 
            }
            buffer.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "false";
        }
    运行的结果如下
    ![图片说明](http://img.ask.csdn.net/upload/201506/12/1434070730_998367.png)

7个回答

tongyi55555
tongyi55555   2015.06.12 09:26

bufferedreader不等于null,不一定读出来的结果就不为null.
要确保你读取的文件中有内容啊。

qq_21108099
qq_21108099   2015.06.12 10:12

怎么看读取的文件是否有内容啊

qq_21108099
qq_21108099   2015.06.12 10:12

怎么看读取的文件是否有内容啊

qq_21108099
qq_21108099   2015.06.12 10:11

怎么看读取的文件是否有内容啊

qq_21108099
qq_21108099   2015.06.12 10:12

怎么看读取的文件是否有内容啊

qq_21108099
qq_21108099   2015.06.12 10:12

怎么看读取的文件是否有内容啊

windsunmoon
windsunmoon   Rxr 2015.06.12 17:59
 /**
     * Reads a line of text.  A line is considered to be terminated by any one
     * of a line feed ('\n'), a carriage return ('\r'), or a carriage return
     * followed immediately by a linefeed.
     *
     * @return     A String containing the contents of the line, not including
     *             any line-termination characters, or null if the end of the
     *             stream has been reached
     *
     * @exception  IOException  If an I/O error occurs
     */
    public String readLine() throws IOException {
        return readLine(false);
    }

以上代码了来自 jdk的实现,很明显,readLine()返回null 就证明 流中 没有数据呗

Csdn user default icon
上传中...
上传图片
插入图片