循环事件可以是哨兵、标志、计数器或EOF。使用num作为我的变量,正确的方法是写这些。这就是我到目前为止的情况,如果错了,请改正。
while (num <=5)while (num !=5)while (num=0; num < 5; num++).谢谢你的帮助。我们对此深表感谢。
发布于 2013-12-03 02:28:31
所有IO调用通常都会在没有或不再读取任何数据时失败。如果使用InputStream读取字节缓冲区,则基本循环如下所示:
InputStream in = …;
byte[] buffer = new byte[512];
int read = -1;
while ((read = stream.read(buffer)) != -1) {
// process contents of buffer
}因为InputStream.read(byte[])的文档声明:
返回: 读入缓冲区的字节总数,如果没有更多的数据,则为-1,因为已经到达流的末尾。
发布于 2013-12-03 02:33:49
我不知道你的术语,但3错了,应该是for(.)而不是。
BufferedReader reader = new BufferedReader(path);
String stuffRead = new String();
try
{
while(true) {
stuffRead += reader.readLine();
}
}
catch(EOFException except){
System.out.println("End of file reached");
}
catch(IOException except){
}https://stackoverflow.com/questions/20341600
复制相似问题