{"id":865,"date":"2019-10-02T18:40:07","date_gmt":"2019-10-02T05:40:07","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=865"},"modified":"2019-10-02T18:40:07","modified_gmt":"2019-10-02T05:40:07","slug":"using-scanner-to-read-a-text-file","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=865","title":{"rendered":"Using Scanner to Read a Text File"},"content":{"rendered":"<p>Reading a text file using <strong>java.util.Scanner<\/strong> in <strong>Java<\/strong>.<\/p>\n<pre style=\"white-space: pre;\">StringBuilder text = new StringBuilder();\r\ntry(Scanner scanner = new Scanner(new BufferedReader(new FileReader(\"&lt;FILENAME&gt;\")))) {\r\n    while(scanner.hasNext()) {\r\n        text.append(scanner.nextLine()).append(\"\\n\");\r\n    }\r\n} catch (FileNotFoundException e) {\r\n    e.printStackTrace();\r\n}\r\nSystem.out.println(text.toString());\r\n<\/pre>\n<p>Where:<\/p>\n<table>\n<tbody>\n<tr>\n<td>FILENAME<\/td>\n<td>The text file to read.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Reading a text file using java.util.Scanner in Java. StringBuilder text = new StringBuilder(); try(Scanner scanner = new Scanner(new BufferedReader(new FileReader(&#8220;&lt;FILENAME&gt;&#8221;)))) { while(scanner.hasNext()) { text.append(scanner.nextLine()).append(&#8220;\\n&#8221;); } } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println(text.toString()); Where: FILENAME The text file to read.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[54],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/865"}],"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=865"}],"version-history":[{"count":2,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":867,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions\/867"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}