Packageflow;ImportJava.io.BufferedReader;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.FileReader;Importjava.io.IOException;ImportJava.io.InputStream; Public classRead { Public Static voidMain (string[] args) {Bufferedreaderdemo (); } Public Static voidInputstreamdemo () {Try{InputStream InputStream=NewFileInputStream ("D://test.txt"); intCh=0; Try { while((Ch=inputstream.read ())!=-1) {System.out.print (Char) ch); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Public Static voidFilereaderdemo () {FileReader filereader; Try{FileReader=NewFileReader ("D://test.txt"); intCh=0; Try { while((Ch=filereader.read ())!=-1) {System.out.print (Char) ch); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Public Static voidBufferedreaderdemo () {Try{BufferedReader BufferedReader=NewBufferedReader (NewFileReader ("D://test.txt")); String data; Try{Data=Bufferedreader.readline (); while(data!=NULL) {System.out.println (data); Data=Bufferedreader.readline (); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Java Stream read