{"id":968,"date":"2019-11-15T18:51:40","date_gmt":"2019-11-15T05:51:40","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=968"},"modified":"2019-11-15T18:51:40","modified_gmt":"2019-11-15T05:51:40","slug":"writing-and-reading-into-and-from-a-text-file-in-gosu","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=968","title":{"rendered":"Writing and Reading Into and From a Text File in Gosu"},"content":{"rendered":"<h3>Writing into a Text File in Gosu<\/h3>\n<p>To <strong>write<\/strong> into a text file in gosu we can use the <strong>FileWriter<\/strong> as follows:<\/p>\n<pre style=\"white-space: pre;\">using(var writer = new BufferedWriter(new FileWriter(\"&lt;FILENAME&gt;\"))) {\r\n  writer.write(\"&lt;TEXT&gt;\")  \/\/ Writes a text to into a file.\r\n  writer.flush() \/\/ Must be at the last.\r\n}\r\n<\/pre>\n<table>\n<tbody>\n<tr>\n<td><strong>Token<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>FILENAME<\/td>\n<td>The target filename to write into.<\/td>\n<\/tr>\n<tr>\n<td>TEXT<\/td>\n<td>The text to write into the filename. You can write as many text as you like. Just don't forget the flush method at the end.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Reading from a Text File in Gosu<\/h3>\n<p>To <strong>read<\/strong> from a text file in gosu we can use the <strong>FileReader<\/strong> with <strong>Scanner<\/strong> as follows:<\/p>\n<pre style=\"white-space: pre;\">using (var scanner = new Scanner(new BufferedReader(new FileReader(\"&lt;FILENAME&gt;\")))) {\r\n  while(scanner.hasNext()) {\r\n    print(scanner.nextLine()) \/\/---Reads a line from the file.\r\n  }\r\n}\r\n<\/pre>\n<table>\n<tbody>\n<tr>\n<td><strong>Token<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>FILENAME<\/td>\n<td>The target filename to read from.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Writing into a Text File in Gosu To write into a text file in gosu we can use the FileWriter as follows: using(var writer = new BufferedWriter(new FileWriter(&#8220;&lt;FILENAME&gt;&#8221;))) { writer.write(&#8220;&lt;TEXT&gt;&#8221;) \/\/ Writes a text to into a file. writer.flush() \/\/ Must be at the last. } Token Description FILENAME The target filename to write into. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/968"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=968"}],"version-history":[{"count":2,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/968\/revisions"}],"predecessor-version":[{"id":970,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/968\/revisions\/970"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}