{"id":2715,"date":"2017-11-27T08:02:06","date_gmt":"2017-11-27T08:02:06","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2715"},"modified":"2017-11-27T08:06:15","modified_gmt":"2017-11-27T08:06:15","slug":"how-to-write-in-the-file-using-filewriter-class-and-bufferedwriter-class-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-write-in-the-file-using-filewriter-class-and-bufferedwriter-class-in-core-java\/","title":{"rendered":"How to Write in the File using FileWriter class and BufferedWriter class in Core Java"},"content":{"rendered":"<p>In this tutorial how to write in the file using FileWriter class and BufferedWriter class in Core Java\u00a0 is shown.<\/p>\n<p>Code:<\/p>\n<p>FileWriterDemo.java<\/p>\n<p>import java.io.*;<\/p>\n<p>class Test1<br \/>\n{<br \/>\npublic static void main(String args[])<br \/>\n{<br \/>\nString fileName=&#8221;temp.txt&#8221;;<br \/>\ntry<br \/>\n{<br \/>\nFileWriter fileWriter = new FileWriter(fileName);<br \/>\nBufferedWriter bufferedWriter = new BufferedWriter(fileWriter);<br \/>\nbufferedWriter.write(&#8220;Hello there,&#8221;);<br \/>\nbufferedWriter.write(&#8221; here is some text.&#8221;);<br \/>\nbufferedWriter.newLine();<br \/>\nbufferedWriter.write(&#8220;We are writing\/reading&#8221;);<br \/>\nbufferedWriter.write(&#8221; the text to the file&#8221;);<br \/>\nbufferedWriter.close();<br \/>\n}<br \/>\ncatch(IOException ex)<br \/>\n{<br \/>\nSystem.out.println(&#8220;Error writing to file &#8216;&#8221;+fileName+&#8221;&#8216;&#8221;);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/Spk5-G6N048\">https:\/\/youtu.be\/Spk5-G6N048<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how to write in the file using FileWriter class and BufferedWriter class in Core Java\u00a0 is shown. Code: FileWriterDemo.java import java.io.*; class Test1 { public static void main(String args) { String fileName=&#8221;temp.txt&#8221;; try { FileWriter fileWriter = new FileWriter(fileName); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(&#8220;Hello there,&#8221;); bufferedWriter.write(&#8221; here is some text.&#8221;); bufferedWriter.newLine(); bufferedWriter.write(&#8220;We are writing\/reading&#8221;); bufferedWriter.write(&#8221; the text to the file&#8221;); bufferedWriter.close(); } catch(IOException ex) { System.out.println(&#8220;Error writing to file &#8216;&#8221;+fileName+&#8221;&#8216;&#8221;); } } }<!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156],"tags":[198,157,197,196],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2715"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2715"}],"version-history":[{"count":3,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2715\/revisions"}],"predecessor-version":[{"id":2719,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2715\/revisions\/2719"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}