{"id":266940,"date":"2015-10-28T10:08:02","date_gmt":"2015-10-28T07:08:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=266940"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=266940","title":{"rendered":"\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f Java \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0447\u0442\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u0430"},"content":{"rendered":"<p>       \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<br \/>  \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e <strike>\u043a\u0440\u0435\u0441\u0442\u044c\u044f\u043d\u0438\u043d\u0430<\/strike> Java \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0447\u0430\u0442\u0438 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/96e\/fcd\/25b\/96efcd25bdd94d0c9830dab16b4991fd.png\"\/><\/p>\n<p>  \u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0430\u0441 \u043f\u043e\u043c\u043d\u044f\u0442<\/p>\n<h2>&#8216;\u0434\u043e Java 7&#8217; \u043c\u0443\u0447\u0435\u043d\u0438\u044f:<\/h2>\n<p>  <\/p>\n<pre><code class=\"java\">        BufferedReader reader = null;         try {             reader = new BufferedReader(                         new InputStreamReader(                             new FileInputStream(FILE_NAME), Charset.forName(&quot;UTF-8&quot;)));             String line;             while ((line = reader.readLine()) != null) {                 System.out.println(line);             }         } catch (IOException e) {             \/\/ log error         } finally {             if (reader != null) {                 try {                     reader.close();                 } catch (IOException e) {                     \/\/ log warning                 }             }         } <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c, \u0440\u0430\u0437\u0432\u0435 \u0447\u0442\u043e   <\/p>\n<h2>Apache <a href=\"https:\/\/commons.apache.org\/proper\/commons-io\/\">Commons IO<\/a><\/h2>\n<p>  <\/p>\n<pre><code class=\"java\">        InputStreamReader in = null;         try {             in = new InputStreamReader(new FileInputStream(new File(FILE_NAME)), Charsets.UTF_8);             LineIterator it = new LineIterator(in);             while (it.hasNext()) {                 System.out.println(it.nextLine());             }         } catch (IOException e) {             \/\/ log error         } finally {             IOUtils.closeQuietly(in);         } <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"java\">        LineIterator it = null;         try {             it = FileUtils.lineIterator(new File(FILE_NAME), &quot;UTF-8&quot;);             while (it.hasNext()) {                 System.out.println(it.nextLine());             }         } catch (IOException e) {             \/\/ log error         } finally {             if (it != null) {                 it.close();             }         } <\/code><\/pre>\n<h2>Java 7<\/h2>\n<p> \u043f\u0440\u0438\u043d\u0435\u0441\u043b\u0430 <a href=\"http:\/\/www.journaldev.com\/592\/try-with-resource-example-java-7-feature-for-automatic-resource-management\">automatic resource management (ARM)<\/a>, <a href=\"http:\/\/www.quizful.net\/post\/java-nio-tutorial\">NIO.2<\/a> \u0438 <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/nio\/charset\/StandardCharsets.html\">StandardCharsets<\/a>. \u0422\u0435\u043f\u0440\u0435\u044c \u0431\u0435\u0437 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c:  <\/p>\n<pre><code class=\"java\">        try (BufferedReader reader = new BufferedReader(                 new InputStreamReader(                         new FileInputStream(FILE_NAME), StandardCharsets.UTF_8))){             String line;             while ((line = reader.readLine()) != null) {                 System.out.println(line);             }         } catch (IOException e) {             \/\/ log error         } <\/code><\/pre>\n<p>  \u0438\u043b\u0438 \u0435\u0449\u0435 \u043a\u043e\u0440\u043e\u0447\u0435:  <\/p>\n<pre><code class=\"java\">            List&lt;String&gt; lines = Files.readAllLines(Paths.get(FILE_NAME), StandardCharsets.UTF_8);             for(String line: lines){                 System.out.println(line);             } <\/code><\/pre>\n<p>  \u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446  <\/p>\n<h2>Java 8<\/h2>\n<p> \u0441\u043e \u0441\u0432\u043e\u0438\u043c <a href=\"http:\/\/prologistic.com.ua\/polnoe-rukovodstvo-po-java-8-stream.html\">Stream API<\/a> \u0438 <a href=\"http:\/\/habrahabr.ru\/post\/224593\/\">\u041b\u044f\u043c\u0431\u0434\u0430-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:  <\/p>\n<pre><code class=\"java\">            Files.lines(Paths.get(FILE_NAME), StandardCharsets.UTF_8).forEach(System.out::println); <\/code><\/pre>\n<p>  \u041c\u043e\u0440\u0430\u043b\u044c: \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f Java \u2014 \u043d\u0430\u0434\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u043e, \u0438 \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u043b\u043e\u0445\u043e.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0443\u0441\u043f\u0435\u0445\u043e\u0432 \u0432 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438!               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/269667\/\"> http:\/\/habrahabr.ru\/post\/269667\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435!<br \/>  \u041f\u0440\u0438\u0432\u0435\u0434\u0443 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0430\u0441\u044c \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e <strike>\u043a\u0440\u0435\u0441\u0442\u044c\u044f\u043d\u0438\u043d\u0430<\/strike> Java \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u043f\u0435\u0447\u0430\u0442\u0438 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/96e\/fcd\/25b\/96efcd25bdd94d0c9830dab16b4991fd.png\"\/><\/p>\n<p>  \u041c\u043d\u043e\u0433\u0438\u0435 \u0438\u0437 \u043d\u0430\u0441 \u043f\u043e\u043c\u043d\u044f\u0442<\/p>\n<h2>&#8216;\u0434\u043e Java 7&#8217; \u043c\u0443\u0447\u0435\u043d\u0438\u044f:<\/h2>\n<p>  <\/p>\n<pre><code class=\"java\">        BufferedReader reader = null;         try {             reader = new BufferedReader(                         new InputStreamReader(                             new FileInputStream(FILE_NAME), Charset.forName(&quot;UTF-8&quot;)));             String line;             while ((line = reader.readLine()) != null) {                 System.out.println(line);             }         } catch (IOException e) {             \/\/ log error         } finally {             if (reader != null) {                 try {                     reader.close();                 } catch (IOException e) {                     \/\/ log warning                 }             }         } <\/code><\/pre>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-266940","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266940"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/266940\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}