{"id":2721,"date":"2017-11-27T08:13:11","date_gmt":"2017-11-27T08:13:11","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2721"},"modified":"2017-11-27T08:13:11","modified_gmt":"2017-11-27T08:13:11","slug":"how-to-write-in-the-file-using-fileoutputstream-class-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-write-in-the-file-using-fileoutputstream-class-in-core-java\/","title":{"rendered":"How to Write in the File using FileOutputStream class in Core Java"},"content":{"rendered":"<p>In this tutorial how to write in the file using FileOutputStream class in Core Java\u00a0 is shown.<\/p>\n<p>Code:<\/p>\n<p>FileOutputStreamDemo.java<\/p>\n<p>import java.io.*;<\/p>\n<p>class Test3<br \/>\n{<br \/>\npublic static void main(String[] args)<br \/>\n{<br \/>\nString fileName=&#8221;temp1.txt&#8221;;<\/p>\n<p>try<br \/>\n{<br \/>\nString bytes=&#8221;Hello there, here is some text.&#8221;;<br \/>\nbyte[] buffer = bytes.getBytes();<br \/>\nFileOutputStream outputStream = new FileOutputStream(fileName);<br \/>\noutputStream.write(buffer);<br \/>\noutputStream.close();<br \/>\nSystem.out.println(&#8220;Wrote &#8220;+buffer.length+&#8221; bytes&#8221;);<br \/>\n}<br \/>\ncatch(IOException ex)<br \/>\n{<br \/>\nSystem.out.println(&#8220;Error writing file &#8216;&#8221;+fileName+&#8221;&#8216;&#8221;);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/YQXO69D6hxo\">https:\/\/youtu.be\/YQXO69D6hxo<\/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 FileOutputStream class in Core Java\u00a0 is shown. Code: FileOutputStreamDemo.java import java.io.*; class Test3 { public static void main(String args) { String fileName=&#8221;temp1.txt&#8221;; try { String bytes=&#8221;Hello there, here is some text.&#8221;; byte buffer = bytes.getBytes(); FileOutputStream outputStream = new FileOutputStream(fileName); outputStream.write(buffer); outputStream.close(); System.out.println(&#8220;Wrote &#8220;+buffer.length+&#8221; bytes&#8221;); } catch(IOException ex) { System.out.println(&#8220;Error writing 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":[157,202,196],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2721"}],"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=2721"}],"version-history":[{"count":2,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2721\/revisions"}],"predecessor-version":[{"id":2723,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2721\/revisions\/2723"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}