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