Reader rdr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(rdr);
String s;
s = br.readLine();
br.close();
Scanner sc = new Scanner(System.in);
s = sc.nextLine();
System.out.print(s);
I've noticed that if I close the BufferedReader
, I won't be able to insert input from the keyboard anymore, as System.in
is somehow closed. Is there anyway I can keep br.close()
(I need that in order to delete a file) and then add more input from the keyboard?
br
in order to delete a file. – KinnardBufferedReader
upto some point and, then close theBufferedReader
and then read more from the file stream, you will miss some bytes. These bytes are consumed by the buffered reader (in order to buffer). You'll need to find another way. Why do you need to go from a Reader subclass to a Scanner? Some api restrictions? In either case, you can do things differently, for example by using aRandomAccessFile
and/or a custom Scanner subclass that can do Reader things too. – Lohrman