Packageflow;ImportJava.io.BufferedWriter;Importjava.io.FileNotFoundException;ImportJava.io.FileOutputStream;ImportJava.io.FileWriter;Importjava.io.IOException;ImportJava.io.OutputStream; Public classWrite { Public StaticString path= "D://test.txt"; Public Static voidMain (string[] args) {Bufferedwriterdemo (); } //Byte stream Public Static voidOutputStream () {Try{outputstream OutputStream=NewFileOutputStream (path); String Str= "Hello World"; byte[] b=str.getbytes (); for(inti=0; i<b.length; i++) Try{outputstream.write (b[i]); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } //character Stream Public Static voidFilewriterdemo () {FileWriter FileWriter; Try{FileWriter=NewFileWriter (path); String Str= "Hello word"; Filewriter.write (str); Filewriter.flush (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } //Buffered Streams Public Static voidBufferedwriterdemo () {BufferedWriter bufferedwriter; Try{BufferedWriter=NewBufferedWriter (NewFileWriter (path)); String Str= "Hello word"; Bufferedwriter.write (str); Bufferedwriter.flush (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } }}
Java Stream Write