{"id":39,"date":"2005-11-18T23:03:09","date_gmt":"2005-11-19T04:03:09","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/?p=39"},"modified":"2005-11-18T23:03:09","modified_gmt":"2005-11-19T04:03:09","slug":"two-write-a-file","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2005\/11\/18\/two-write-a-file\/","title":{"rendered":"Two Write A File"},"content":{"rendered":"<p>I learned how to print text in Java using System.out, so it was natural for me to use the PrintStream to write text out to a file.  Here is how I used to write text to a file:<\/p>\n<pre>\nFileOutputStream fos = new FileOutputStream(filePathStr);\nPrintStream ps = new PrintStream(fos);\nps.println(&quot;Hello, World!&quot;);\nps.close();\n<\/pre>\n<p>To write some quick debugging message to a file I would sometimes use the FileWriter as in the following example:<\/p>\n<pre>\nFileWriter fw = new FileWriter(filePathStr);\nfw.write(&quot;Hello, World!&quot;);\nfw.close();\n<\/pre>\n<p>Now with Java 1.5 I am exclusively using the PrintWriter.  Unlike FileWriter, Printwriter defines and overloads all my favorite println methods that I am so used to by from the years of using the System.out PrintStream.<\/p>\n<pre>\nPrintWriter pw = new PrintWriter(filePathStr);\npw.println(&quot;Hello, World!&quot;);\npw.close();\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I learned how to print text in Java using System.out, so it was natural for me to use the PrintStream to write text out to a file. Here is how I used to write text to a file: FileOutputStream fos = new FileOutputStream(filePathStr); PrintStream ps = new PrintStream(fos); ps.println(&quot;Hello, World!&quot;); ps.close(); To write some quick [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[15,3],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-D","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/39"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}