Java Bufferedwriter Example - Java

How to use java bufferedwriter concept?

Snippet Code

Rate this page :
  [ 0 votes]

BufferedWriter in java is a character output stream class which is used to handle the character data. Buffered writer which is used to write the strings, arrays or characters data directly into the file.

import; import; import; public class BufferedWriterDemo { public static void main(String[] args) throws IOException { StringWriter sw = null; BufferedWriter bw = null; String str = "Welcome to Hscripts!"; try{ sw = new StringWriter(); bw = new BufferedWriter(sw); bw.write(str); bw.flush(); StringBuffer sb = sw.getBuffer(); System.out.println(sb); }catch(IOException e){ e.printStackTrace(); }finally{ if(sw!=null) sw.close(); if(bw!=null) bw.close(); } } }


Ask Questions

Ask Question