我想读取此字符串(来自控制台而不是文件),例如:
one two three
four five six
seven eight nine
Run Code Online (Sandbox Code Playgroud)
所以我想每行读取它并将每一行放在一个数组中.我怎么读呢?因为如果我使用扫描仪,我只能读一行或一个单词(下一行或下一行).
我的意思是阅读例如: one two trhee \n four five six \n seven eight nine...
你应该自己做!有一个similer示例:
public class ReadString {
public static void main (String[] args) {
// prompt the user to enter their name
System.out.print("Enter your name: ");
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userName = null;
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
userName = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error trying to read your name!");
System.exit(1);
}
System.out.println("Thanks for the name, " + userName);
}
} // end of ReadString class
Run Code Online (Sandbox Code Playgroud)