我想在csv文件中输入整数,从控制台读取它,并希望在用户输入Stop时退出。如何在此处验证字符串和数字
答案 0 :(得分:1)
FileOutputStream fo = new FileOutputStream("<Outputfile>");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fo));
Scanner sc = new Scanner(System.in);
String strLine;
while ((strLine = sc.nextLine()) != null) {
if (strLine.equalsIgnoreCase("stop")) {
break;
}
bw.write(strLine);
bw.newLine();
}
bw.close();