开发者

input.read() func. stack the while loop [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

After connecting to server, I run some commands on server and then trying to take the server knowledge to console with;

int i = 0;
byte[] 开发者_Go百科bx = new byte[1];
try {
    while ((i = input.read()) != 10 ) {
        bx[0] = (byte) i;
        System.out.print(new String(bx));
    }
} catch (IOException e1) {
    e1.printStackTrace();
}

but if I run this loop more than one and if the line (which it try to read) is empty it stacks and don't let the program to stop.I tried to check empty line by string check or -1 check but it doesn't work. How can I solve this problem?


Change that:

while ((i = input.read()) != 10 )

To that:

while (((i = input.read()) != 10 ) && (i != -1) )

To check for EOF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜