Reader如何捕获eof

发布于 12-20 06:59 字数 279 浏览 3 评论 0原文

我对 catch EOF 字符有疑问。

int y = read();
char x = (char) y;
System.out.println(y);
return x;   

但是当我得到 EOF 时,它返回 10 并关闭流。我尝试了准备,但它不起作用。 :( 编辑 如何向正在读取 System.in 的程序发出 EOF 信号 NetBeans 控制台? 我将尝试使用 eclipse 控制台,因为其他读者也可以工作。 编辑 问题已解决,可在 eclipse 上使用

I have a problem with the catch EOF character.

int y = read();
char x = (char) y;
System.out.println(y);
return x;   

But when I get EOF it returns 10 and closes the stream. I tried with ready, but it doesn't work. :(
EDIT
How do I signal EOF to a program that is reading System.in from the
NetBeans console?
I will try with eclipse console cuz other Readers works.
EDIT
Problem solved works on eclipse

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼波传意2024-12-27 06:59:48

Ready() 不会帮助您,因为可以读取流,下一个字符恰好是 EOF。

我不确定你想要做什么,但如果你想防止返回 EOF 字符,你应该添加一个检查。

int y = read();
if( -1 == y ) {
    // Handle it however you want
}

Ready() won't help you with that since the stream can be read from, the next character just happens to be EOF.

I am not sure what you are looking to do, but if you want to prevent returning the EOF character, you should add a check for it.

int y = read();
if( -1 == y ) {
    // Handle it however you want
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文