与System.in.read()一起使用的文件结束/流键盘组合是什么 [英] What is the End Of File/Stream keyboard combination to use with System.in.read()

查看:63
本文介绍了与System.in.read()一起使用的文件结束/流键盘组合是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,这个琐碎的问题已经回答了,我无法在SO上找到它.使用此Java普通代码(Windows 7和Eclipse Kepler)从IDE控制台读取行:

Apologize if this trivial question has already been answered, I cannot find it at SO. Reading lines from the IDE console with this Java trivial code (Windows 7 and Eclipse Kepler):

int v;
try { while ((v = System.in.read()) != -1) System.out.println(v); }
catch (IOException e) { ; }

用户如何使值v等于-1?(我试过 Ctrl + d - z - x - c - s - e 和其他键没有可重复的行为,但是循环是随机中断的)

How the user can make the value v equal to -1? (I've tried Ctrl + d-z-x-c-s-e and other keys without repeatable behavior, but the loop is interrupted randomly)

推荐答案

Control + D 应该发送EOF字符作为例外,但这是Eclipse中的一个错误.

Control + D should send the EOF character as excepted , but it is an bug in Eclipse.

其中一位用户报告为

    In Kepler 4.3 eclipse.buildId=4.3.0.M20130911-1000 on Linux the problem 
    still exists in the Java console. I found the following workaround:

    If you leave the console to focus on another view, and then refocus on the console,
    then Ctrl-D (EOF) works as expected.

按照此处

在Windows中使用Eclipse时, Control + Z 发送EOF字符.

When using Eclipse in Windows, Control + Z sends the EOF character.

这篇关于与System.in.read()一起使用的文件结束/流键盘组合是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆