我正在用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编码