我想知道Java SE是否有一种方法可以打印出一段段落,然后在行之间我们可以允许用户在行上键入答案。
要更清楚:
这是一个例子:
_ __ _读书,爱丽丝也喜欢听古典音乐。
因此,当使用缓冲区阅读器绘制文本时,用户可以在行本身上输入答案。
这是缓冲区读取器的方法:
public void getCloze(){
File file = new File("cloze.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null) {
contents.append(text)
.append(System.getProperty(
"line.separator"));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
// show file contents here
System.out.println(contents.toString());
}}
如果有任何教程来显示这些步骤,希望有人能告诉我如何和最好的。