Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当循环无限运行时,don';我不明白为什么_Java_Android - Fatal编程技术网

Java 当循环无限运行时,don';我不明白为什么

Java 当循环无限运行时,don';我不明白为什么,java,android,Java,Android,while循环无限运行。能告诉我为什么吗?我试过另一种方法,但对我不起作用 回答并帮助解决问题 有什么问题写了我不打印退出状态 JSch jsch = new JSch(); Session session = jsch.getSession(userName, host); session.setPassword(passWord); session.setConfig("StrictHostKey

while
循环无限运行。能告诉我为什么吗?我试过另一种方法,但对我不起作用

回答并帮助解决问题 有什么问题写了我不打印退出状态

            JSch jsch = new JSch();
            Session session = jsch.getSession(userName, host);
            session.setPassword(passWord);
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
            System.out.print("Conected");
            channel = session.openChannel("shell");
            ops = channel.getOutputStream();
            ps = new PrintStream(ops, true);
            channel.connect();
            //Log.e(Keyid,"Channel Connected");
            ps.println("ls");
            //  ps.println("dir");
            //give commands to be executed inside println.and can have any no of commands sent.
            ps.close();
            InputStream in = channel.getInputStream();
           // BufferedReader input = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            //System.out.println(input.ready());
            //String str = input.readLine();


            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            String line= buffer.readLine();
            while (line != null && !line.equals("")){
              //  length = length + line.length();
                line= buffer.readLine();
                System.out.println(buffer.readLine());

            }
            System.out.println("Exit");

           /* while(buffer.readLine() != null){
                System.out.println(buffer.readLine());
                System.err.println(buffer.ready());

            }*/
用这个
虽然(dataIn.readLine!=null)

我认为这里的问题是该方法比较字符串。但是该方法返回的是逻辑
null
,而不是“null”字符串。因此,比较失败

尝试将其替换为以下内容:

while (dataIn.readLine() != null){

顺便说一句,您将使用上述逻辑打印备用行,您尝试了其他哪种方法?你读过
readLine
equals
方法的javadocs吗?虽然(dataIn.readLine()!=null)不工作,但我要求DataInputStream dataIn=new DataInputStream(channel.getInputStream());用于while循环