BufferedReader

时间:2018-01-08 17:07:56

标签: java

以下是我目前的编码:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class DictionarySearch{

  public static void main(String[] args) throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = "";
    List<String> dicts = new ArrayList<>();

    line = br.readLine();

    while (line != null && !(line.trim().isEmpty())) {
      dicts.add(line);
      line = br.readLine();
    }

    System.out.println("Done adding");
    String partial = br.readLine();
    System.out.println("Partial: " + partial);
  }
}

当我运行测试时,我将以下值放入控制台:

A
B
C

当我调试代码时,dicts成功包含字符串A和字符串B,但我无法使partial等于C。这是否意味着我使用了错误的类来从控制台读取输入?

0 个答案:

没有答案