As far I know, the two most common methods of reading character-based data from a file in Java is using Scanner
or BufferedReader
. I also know that
Difference between BufferedReader and Scanner are following:
Code to read a line from console:
BufferedReader:
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(isr);
String st= br.readLine();
Scanner:
Scanner sc= new Scanner(System.in);
String st= sc.nextLine();