public static String readInput() throws IOException {
BufferedReader br;
String str = "";
// 从键盘读取一行输入,回车结束
br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
return str;
}或者使用
Scanner sc = new Scanner(System.in);
System.out.println("请输入你想要得字符串:");
String str = sc.nextLine();
System.out.println("你输入的字符串为:" + str);