为什么敲回车后它不停止输入呢?而是回车后换行还可以无限输入,实在是不知道哪里错了
import java.io.*;
import java.util.*;
public class Test{
public static void main(String[] args)throws Exception{
BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\haha.txt"));
System.out.println("Please Enter Something:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
while(s != null){
bw.write(s);
bw.newLine();
s = sc.nextLine();
}
bw.flush();
bw.close();
}
}