代码之家  ›  专栏  ›  技术社区  ›  Dark 98

ReadLine(缓冲读取器)不在循环中工作

  •  1
  • Dark 98  · 技术社区  · 2 年前

    我正在用Intelij编写代码。readLine无法正确读取输入(在行尾放一个换行符),这就是为什么下一个readLine无法工作(自动变为空)。 代码:

    public class Start {
        public static void main(String[] args) throws IOException {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String s = reader.readLine();
            ArrayList<String> list = new ArrayList<>();
            while (true) {
                if (s == null || s.isEmpty()) {
                    break;
                }
                else list.add(s);
                s = reader.readLine();
            }
    
            for (String str : list) {
                System.out.println(str);
            }
    

    如果重要:LF分隔符和UTF-8编码

    1 回复  |  直到 2 年前
        1
  •  0
  •   CrazyCoder    2 年前

    这是一个 know bug . 修复程序已可用,请 update .