{"id":187,"date":"2024-08-14T10:39:08","date_gmt":"2024-08-14T01:39:08","guid":{"rendered":"https:\/\/techfun.cc\/?p=187"},"modified":"2025-06-02T12:51:00","modified_gmt":"2025-06-02T03:51:00","slug":"java_base_stream","status":"publish","type":"post","link":"https:\/\/techfun.cc\/java-base\/java_base_stream.html","title":{"rendered":"\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0"},"content":{"rendered":"<h3 class=\"Heading Title Title--m\" id=\"Bookmark-1\"><span class=\"Num\">1.<\/span>\u672c\u7ae0\u3067\u306e\u5b66\u7fd2\u9805\u76ee<\/h3>\n<p>\u672c\u7ae0\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3093\u3060\u308a\u3059\u308b\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u95a2\u3057\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002<\/p>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-2\"><span class=\"Num\">2.<\/span>\u672c\u7ae0\u306e\u8b1b\u7fa9<\/h3>\n<p>\u672c\u7ae0\u3067\u5b66\u7fd2\u3059\u308b\u5185\u5bb9\u3092\u52d5\u753b\u3068\u3057\u3066\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3059\u3002\u6700\u521d\u306b\u4e00\u901a\u308a\u898b\u7d42\u308f\u3063\u305f\u5f8c\u3067\u3001\u5b66\u7fd2\u306b\u5165\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"Video-block\">\n<div class=\"Video-block__title\">\u8b1b\u7fa9:\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0<\/div>\n<div class=\"Video-block__video Youtube\">\n\t\t<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube-nocookie.com\/embed\/zePYRcZQdpU?si=scjYh1sCzTVFTkXi&#038;rel=0\"\n\t\t\ttitle=\"YouTube video player\" frameborder=\"0\"\n\t\t\tallow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n\t\t\treferrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p><\/div>\n<\/div>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-3\"><span class=\"Num\">3.<\/span>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3068\u306f<\/h3>\n<p>\u3053\u306e\u7ae0\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306e\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u3084\u3001\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u307f\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u306a\u3069\u3001Java\u306e\u74b0\u5883\u3067\u3042\u308bJVM\u304b\u3089\u898b\u308b\u3068\u3001\u5916\u90e8\u8981\u7d20\u3068\u306a\u308b\u30d5\u30a1\u30a4\u30eb\u3084Eclipse\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3068\u306e\u30c7\u30fc\u30bf\u306e\u3084\u308a\u3068\u308a\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002<\/p>\n<p>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3068\u306f\u3001JVM\u3068\u30d5\u30a1\u30a4\u30eb\u30c7\u30fc\u30bf\u3084Eclipse\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3068\u3092\u3084\u308a\u3068\u308a\u3059\u308b\u305f\u3081\u306b\u7528\u3044\u3089\u308c\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002<br \/>\n\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306f\u3001\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u30c7\u30fc\u30bf\u3092\u3084\u308a\u3068\u308a\u3067\u304d\u308b\u3088\u3046\u306b\u30c7\u30fc\u30bf\u5f62\u5f0f\u3092\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a class=\"Ext Image-link\" href=\"https:\/\/techfun.cc\/wp-content\/uploads\/2024\/06\/iostream.png\"><br \/>\n\t<img decoding=\"async\" src=\"https:\/\/techfun.cc\/wp-content\/uploads\/2024\/06\/iostream.png\" alt=\"iostream\"><br \/>\n<\/a><\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-3-1\"><span class=\"Num\">3.1.<\/span>\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u7a2e\u985e<\/h4>\n<p>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u5206\u985e\u3059\u308b\u3068\u3001\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u6271\u3046\u305f\u3081\u306e\u300c\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u300d\u3068\u753b\u50cf\u3084\u97f3\u58f0\u306a\u3069\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u305f\u3081\u306e\u300c\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u300d\u304c\u3042\u308a\u3001\u305d\u308c\u305e\u308c\u5225\u306e\u30af\u30e9\u30b9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-1-1\"><span class=\"Num\">3.1.1.<\/span>\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0<\/h5>\n<p>\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u3068\u306f\u3001\u305d\u306e\u540d\u306e\u3068\u304a\u308a\u6587\u5b57\u306e\u30c7\u30fc\u30bf\u3092\u3084\u308a\u3068\u308a\u3059\u308b\u30b9\u30c8\u30ea\u30fc\u30e0\u3067\u3059\u3002<\/p>\n<p>\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u4ee3\u8868\u7684\u306a\u30af\u30e9\u30b9\u306f\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002\u4f7f\u3044\u65b9\u306f\u5f8c\u8ff0\u3057\u307e\u3059\u306e\u3067\u3001\u78ba\u8a8d\u3060\u3051\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<table class=\"Base-table\">\n<colgroup>\n<col>\n<col>\n\t<\/colgroup>\n<thead>\n<tr>\n<th colspan=\"2\">\u5165\u529b\uff08Reader\uff09<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"Nowrap\">BufferedReader<\/td>\n<td>\u5165\u529b\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u3057\u3066\u3001\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u52b9\u7387\u7684\u306b\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">FileReader<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u7c21\u6613\u7684\u306b\u8aad\u307f\u8fbc\u307f\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">InputStreamReader<\/td>\n<td>\u6307\u5b9a\u3055\u308c\u305f\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u3063\u3066\u3001\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u3093\u3067\u6587\u5b57\u306b\u5909\u63db\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<th colspan=\"2\">\u51fa\u529b\uff08Writer\uff09<\/th>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">BufferedWriter<\/td>\n<td>\u51fa\u529b\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u3057\u3066\u3001\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u52b9\u7387\u7684\u306b\u30c7\u30fc\u30bf\u3092\u51fa\u529b\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">OutputStreamWriter<\/td>\n<td>\u6307\u5b9a\u3055\u308c\u305f\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u3063\u3066\u3001\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u6587\u5b57\u306b\u5909\u63db\u3057\u3066\u51fa\u529b\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">FileWriter<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u306b\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u7c21\u6613\u7684\u306b\u51fa\u529b\u3057\u307e\u3059<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u306f\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u3088\u308a\u3082\u5165\u51fa\u529b\u304c\u52b9\u7387\u7684\u3067\u3059\u306e\u3067\u3001\u901a\u5e38\u306f\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-1-2\"><span class=\"Num\">3.1.2.<\/span>\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0<\/h5>\n<p>\u753b\u50cf\u306e\u30c7\u30fc\u30bf\u306a\u3069\u3092\u6271\u3046\u3068\u304d\u306f\u3001\u30d0\u30a4\u30c8\u5f62\u5f0f\u3067\u30c7\u30fc\u30bf\u306e\u3084\u308a\u3068\u308a\u3092\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u304c\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n<table class=\"Base-table\">\n<colgroup>\n<col>\n<col>\n\t<\/colgroup>\n<thead>\n<tr>\n<th colspan=\"2\">\u5165\u529b\uff08InputStream\uff09<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"Nowrap\">DataInputStream<\/td>\n<td>\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u57fa\u672c\u30c7\u30fc\u30bf\u578b\u306e\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">FileInputStream<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<th colspan=\"2\">\u51fa\u529b\uff08OutputStream\uff09<\/th>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">DataOutputStream<\/td>\n<td>\u30d0\u30a4\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u57fa\u672c\u30c7\u30fc\u30bf\u578b\u306e\u30c7\u30fc\u30bf\u3092\u51fa\u529b\u3057\u307e\u3059<\/td>\n<\/tr>\n<tr>\n<td class=\"Nowrap\">FileOutputStream<\/td>\n<td>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30d0\u30a4\u30c8\u30c7\u30fc\u30bf\u3092\u51fa\u529b\u3057\u307e\u3059<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-3-2\"><span class=\"Num\">3.2.<\/span>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u51e6\u7406\u6982\u8981<\/h4>\n<p>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u51e6\u7406\u624b\u9806\u306f\u3001\u57fa\u672c\u7684\u306b\u6c7a\u307e\u3063\u3066\u3044\u307e\u3059\u3002\u5404\u51e6\u7406\u306e\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a18\u8ff0\u306b\u3064\u3044\u3066\u306f\u5f8c\u3067\u8aac\u660e\u3057\u307e\u3059\u306e\u3067\u3001\u307e\u305a\u306f\u51e6\u7406\u306e\u6d41\u308c\u3092\u3056\u3063\u304f\u308a\u3068\u898b\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-2-1\"><span class=\"Num\">3.2.1.<\/span>\u5165\u529b\u306e\u51e6\u7406\u624b\u9806<\/h5>\n<p>\u5165\u529b\u306e\u51e6\u7406\u624b\u9806\u306e\u57fa\u672c\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol class=\"Base-list Base-list--ol\">\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u958b\u304f<\/span><br \/>\n\t\t\u307e\u305a\u6700\u521d\u306b\u3001\u5165\u529b\u7528\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u307e\u3059\u3002\n\t<\/li>\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080<\/span><br \/>\n\t\t\u6b21\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002\u901a\u5e38\u306f1\u884c\u305a\u3064\u8aad\u307f\u8fbc\u307f\u3057\u307e\u3059\u3002\n\t<\/li>\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u308b<\/span><br \/>\n\t\t\u6700\u5f8c\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u307e\u3059\u3002\n\t<\/li>\n<\/ol>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-2-2\"><span class=\"Num\">3.2.2.<\/span>\u51fa\u529b\u306e\u51e6\u7406\u624b\u9806<\/h5>\n<p>\u51fa\u529b\u306e\u51e6\u7406\u624b\u9806\u306e\u57fa\u672c\u306f\u3001\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002\u5165\u529b\u3068\u540c\u3058\u3088\u3046\u306a\u624b\u9806\u3067\u3059\u3002<\/p>\n<ol class=\"Base-list Base-list--ol\">\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u958b\u304f<\/span><br \/>\n\t\t\u307e\u305a\u6700\u521d\u306b\u3001\u51fa\u529b\u7528\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u307e\u3059\u3002\n\t<\/li>\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3080<\/span><br \/>\n\t\t\u6b21\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002\n\t<\/li>\n<li class=\"Base-list__child\">\n\t\t<span class=\"Text-highlight\">\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u308b<\/span><br \/>\n\t\t\u6700\u5f8c\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u307e\u3059\u3002\n\t<\/li>\n<\/ol>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-2-3\"><span class=\"Num\">3.2.3.<\/span>\u5165\u51fa\u529b\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u30a4\u30f3\u30dd\u30fc\u30c8<\/h5>\n<p>\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b\u3092\u884c\u3046\u306b\u306f\u3001\u307e\u305a\u3001\u5165\u51fa\u529b\u30d1\u30c3\u30b1\u30fc\u30b8\u300cjava.io\u300d\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3053\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u3084\u30b3\u30f3\u30bd\u30fc\u30eb\u3068\u306e\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b\u3092\u884c\u3046\u305f\u3081\u306e\u30af\u30e9\u30b9\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-3-2-4\"><span class=\"Num\">3.2.4.<\/span>\u5165\u51fa\u529b\u306e\u4f8b\u5916\u51e6\u7406<\/h5>\n<p>\u5165\u51fa\u529b\u306e\u51e6\u7406\u306f\u3001\u4f8b\u5916\u51e6\u7406\u304c\u5fc5\u9808\u3067\u3059\u3002\u4f8b\u5916\u51e6\u7406\u3092\u304d\u3061\u3093\u3068\u884c\u308f\u306a\u3044\u3068\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u901a\u308a\u307e\u305b\u3093\u3002<br \/>\n\u5165\u51fa\u529b\u3067\u4f7f\u7528\u3055\u308c\u308b\u4f8b\u5916\u30af\u30e9\u30b9\u3068\u3057\u3066IOException\u30af\u30e9\u30b9\u3092\u899a\u3048\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u6982\u8981\u306f\u3064\u304b\u3081\u305f\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u308c\u3067\u306f\u3001\u5404\u51e6\u7406\u30d1\u30bf\u30fc\u30f3\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a18\u8ff0\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-4\"><span class=\"Num\">4.<\/span>\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0<\/h3>\n<p>\u307e\u305a\u306f\u3001\u6587\u5b57\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u5404\u51e6\u7406\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-4-1\"><span class=\"Num\">4.1.<\/span>\u30c7\u30fc\u30bf\u306e\u5165\u529b<\/h4>\n<p>\u30c7\u30fc\u30bf\u306e\u5165\u529b\u51e6\u7406\u3068\u3057\u3066\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u3068\u30d5\u30a1\u30a4\u30eb\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u306b\u3064\u3044\u3066\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-4-1-1\"><span class=\"Num\">4.1.1.<\/span>\u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u6587\u5b57\u8aad\u307f\u8fbc\u307f<\/h5>\n<p>Eclipse\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u6587\u5b57\u3092\u5165\u529b\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u51e6\u7406\u306e\u5b66\u7fd2\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u306f\u3001\u5b9f\u884c\u3059\u308b\u3068\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u5165\u529b\u3067\u304d\u307e\u3059\u3002\u5165\u529b\u3057\u3066\u300cEnter\u300d\u30ad\u30fc\u3092\u62bc\u4e0b\u3059\u308b\u3068\u3001\u5165\u529b\u3057\u305f\u6587\u5b57\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<br \/>\n\u300c!\u300d\u3092\u5165\u529b\u3059\u308b\u3068\u5165\u529b\u306e\u5f85\u6a5f\u72b6\u614b\u304c\u7d42\u4e86\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTest1.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOTest1 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\" \u300c!\u300d\uff0b Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\tBufferedReader br = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\t\/\/ ! \u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u5165\u529b\u3059\u308b\u307e\u3067\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\r\n\t\t\twhile (!str.equals(\"!\")) {\r\n\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\");\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u8aad\u307f\u8fbc\u307f\u3001str\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\r\n\t\t\t\tstr = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\tSystem.out.println(\"\u5165\u529b\u3057\u305f\u5024\u306f\u300c\" + str + \"\u300d\u3067\u3059\u3002\");\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5b9f\u884c\u7d50\u679c\u3067\u306f\u3001\u300c33\u300d\u3092\u5165\u529b\u3057\u3066Enter\u30ad\u30fc\u3092\u62bc\u4e0b\u3057\u3001\u305d\u306e\u5f8c\u306b\u300caaa\u300d\u3092\u5165\u529b\u3057\u3066Enter\u30ad\u30fc\u3092\u62bc\u4e0b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">\u56f31 \u5b9f\u884c\u7d50\u679c<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>\u300c!\u300d \uff0b Enter\u3067\u7d42\u4e86\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n33\r\n\u5165\u529b\u3057\u305f\u5024\u306f\u300c33\u300d\u3067\u3059\u3002\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\naaa\r\n\u5165\u529b\u3057\u305f\u5024\u306f\u300caaa\u300d\u3067\u3059\u3002\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt<\/code><\/pre>\n<p>\u305d\u308c\u3067\u306f\u3001\u5404\u51e6\u7406\u306e\u89e3\u8aac\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305a\u3001\u4ee5\u4e0b\u306e\u6587\u3067\u6587\u5b57\u306e\u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>BufferedReader br = null;\r\n\r\n\/\/ \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\nbr = new BufferedReader(new InputStreamReader(System.in));<\/code><\/pre>\n<p>\u300cSystem.in\u300d\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3068\u306a\u308a\u307e\u3059\u3002\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u5165\u529b\u3055\u308c\u305f\u5024\u3092InputStreamReader\u30af\u30e9\u30b9\u3067\u6587\u5b57\u306b\u5909\u63db\u3057\u3001\u305d\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u3059\u308b\u305f\u3081\u306b\u3001BufferedReader\u30af\u30e9\u30b9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3082\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u4e00\u6587\u304c\u5165\u529b\u3055\u308c\u305f\u6587\u5b57\u306e\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u3067\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u8aad\u307f\u8fbc\u307f\u3001str\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\r\nstr = br.readLine();<\/code><\/pre>\n<p>\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u30891\u884c\u8aad\u307f\u8fbc\u3080\u306b\u306f\u3001readLine\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u8aad\u307f\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u3092str\u3068\u3044\u3046\u5909\u6570\u306b\u4ee3\u5165\u3057\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u4ee5\u4e0b\u306e\u4e00\u6587\u3067\u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\nbr.close();<\/code><\/pre>\n<p>\u3053\u306e\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u5fd8\u308c\u308b\u3068\u3001\u4e0d\u8981\u306a\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u60c5\u5831\u3092\u4fdd\u6301\u3057\u7d9a\u3051\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u5fd8\u308c\u305a\u306b\u30af\u30ed\u30fc\u30ba\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3082\u3057\u306a\u304f\u3066\u3082\u3001\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u306f\u5fc5\u305a\u5b9f\u65bd\u3057\u305f\u3044\u305f\u3081\u3001finally\u53e5\u306e\u4e2d\u3067\u884c\u3046\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6700\u5f8c\u306b\u3001\u4ee5\u4e0b\u306e\u4e00\u6587\u3067IOException\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u3001\u30a8\u30e9\u30fc\u5185\u5bb9\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\ne.printStackTrace();<\/code><\/pre>\n<p>printStackTrace\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u767a\u751f\u3057\u305f\u4f8b\u5916\u306e\u30af\u30e9\u30b9\u540d\u3084\u4f8b\u5916\u306e\u8aac\u660e\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u884c\u756a\u53f7\u306a\u3069\u3001\u3069\u3053\u3067\u3069\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u304b\u3092\u8a73\u3057\u304f\u51fa\u529b\u3057\u3066\u304f\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n\u4f8b\u5916\u767a\u751f\u539f\u56e0\u3092\u7279\u5b9a\u3059\u308b\u305f\u3081\u306e\u60c5\u5831\u3068\u3057\u3066\u975e\u5e38\u306b\u5f79\u7acb\u3061\u307e\u3059\u306e\u3067\u3001\u7279\u306b\u7406\u7531\u304c\u7121\u3044\u9650\u308a\u306f\u3001catch\u53e5\u306e\u4e2d\u306b\u6c7a\u307e\u308a\u3054\u3068\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u51e6\u7406\u306e\u8aac\u660e\u306f\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-4-1-2\"><span class=\"Num\">4.1.2.<\/span>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306e\u6587\u5b57\u8aad\u307f\u8fbc\u307f<\/h5>\n<p>\u6b21\u306b\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u51e6\u7406\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3068\u306f\u3001\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u4fdd\u5b58\u3059\u308b\u30c7\u30fc\u30bf\u306e\u7a2e\u985e\u306f\u3044\u308d\u3044\u308d\u3042\u308a\u3001\u6587\u5b57\u30c7\u30fc\u30bf\u3084\u753b\u50cf\u3001\u97f3\u306a\u3069\u3001\u901a\u5e38OS\u306f\u591a\u6570\u306e\u7a2e\u985e\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u97f3\u697d\u3067\u3042\u308c\u3070mp3\u30d5\u30a1\u30a4\u30eb\u3084\u3001AAC\u30d5\u30a1\u30a4\u30eb\u3001\u753b\u50cf\u3067\u3042\u308c\u3070GIF\u30d5\u30a1\u30a4\u30eb\u3084\u3001JPEG\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<br \/>\n\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u7d4c\u7531\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u64cd\u4f5c\u3059\u308b\u305f\u3081\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5b58\u5728\u3092\u3042\u307e\u308a\u8a8d\u8b58\u3057\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u7121\u3057\u3067\u306f\u30c7\u30fc\u30bf\u306e\u53d7\u3051\u6e21\u3057\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u306b\u306f\u5927\u304d\u304f\u5206\u3051\u3066\u300c\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u300d\u3068\u300c\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u300d\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<br \/>\n\u300c\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u300d\u306f\u6587\u5b57\u30c7\u30fc\u30bf\u306e\u307f\u3067\u69cb\u6210\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\u901a\u5e38\u300c\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u300d\u3068\u547c\u3070\u308c\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u3088\u3063\u3066\u8aad\u3080\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br \/>\nWindows\u306e\u6a19\u6e96\u300c\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u300d\u306f\u300c\u30e1\u30e2\u5e33\u300d\u3068\u3044\u3046\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306f\u3001\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3055\u308c\u305f\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u51e6\u7406\u306b\u3064\u3044\u3066\u78ba\u8a8d\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3080\u306b\u306f\u3001FileReader\u30af\u30e9\u30b9\u3092\u4f7f\u3044\u307e\u3059\u3002\u8aad\u307f\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u306f\u3001BufferedReader\u30af\u30e9\u30b9\u306b\u3088\u3063\u3066\u3001\u30d0\u30c3\u30d5\u30a1\u3068\u547c\u3070\u308c\u308b\u4e00\u6642\u7684\u306b\u4fdd\u5b58\u3059\u308b\u30e1\u30e2\u30ea\u30fc\u306b\u4fdd\u5b58\u3055\u308c\u307e\u3059\u3002<br \/>\n\u3042\u3068\u306f\u30d0\u30c3\u30d5\u30a1\u306b\u4fdd\u5b58\u3055\u308c\u305f\u30c7\u30fc\u30bf\u30921\u884c\u305a\u3064\u8aad\u307f\u8fbc\u3093\u3067\u51e6\u7406\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u300cC:\\temp\uff08C\u30c9\u30e9\u30a4\u30d6\u306etemp\u30d5\u30a9\u30eb\u30c0\uff09\u300d\u306b\u30d5\u30a1\u30a4\u30eb\u300ctemp1.txt\u300d\u3092\u4f5c\u6210\u3057\u3001\u4f55\u304b\u6587\u5b57\u3092\u66f8\u3044\u3066\u4fdd\u5b58\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002temp\u30d5\u30a9\u30eb\u30c0\u304c\u7121\u3044\u5834\u5408\u3001\u65b0\u305f\u306b\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u306f\u3001C:\\temp\uff08C\u30c9\u30e9\u30a4\u30d6\u306etemp\u30d5\u30a9\u30eb\u30c0\uff09\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u300ctemp1.txt\u300d\u304b\u3089\u30c7\u30fc\u30bf\u3092\u30d0\u30c3\u30d5\u30a1\u306b\u8aad\u307f\u8fbc\u307f\u30011\u884c\u305a\u3064\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30d0\u30c3\u30d5\u30a1\u304b\u30891\u884c\u305a\u3064\u8aad\u307f\u8fbc\u3080\u306b\u306f\u3001\u4e0a\u8a18\u306e\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u3082\u4f7f\u3063\u305freadLine\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTest2.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.FileReader;\r\nimport java.io.IOException;\r\n\r\npublic class IOTest2 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\t\/\/ \u958b\u59cb\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u51fa\u529b\u3057\u307e\u3059\r\n\t\tSystem.out.println(\"\u30d5\u30a1\u30a4\u30ebtemp1.txt\u304b\u3089\u30d0\u30c3\u30d5\u30a1\u306b\u8aad\u307f\u8fbc\u3080\");\r\n\r\n\t\tBufferedReader br = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbr = new BufferedReader(new FileReader(\"C:\\\\temp\\\\temp1.txt\"));\r\n\r\n\t\t\tString str = null;\r\n\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u8907\u6570\u884c\u6587\u5b57\u304c\u8a18\u8ff0\u3055\u308c\u3066\u308b\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u7e70\u308a\u8fd4\u3057\u51e6\u7406\r\n\t\t\twhile ((str = br.readLine()) != null) {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u4e00\u884c\u305a\u3064\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\tSystem.out.println(str);\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3068\u307b\u3068\u3093\u3069\u540c\u3058\u3088\u3046\u306a\u8a18\u8ff0\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u8aad\u307f\u8fbc\u3080\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>BufferedReader br = null;\r\n\r\n\/\/ \u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\nbr = new BufferedReader(new FileReader(\"C:\\\\temp\\\\temp1.txt\"));<\/code><\/pre>\n<p>FileReader\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u6307\u5b9a\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u300c&quot;C:\\\\temp\\\\temp1.txt&quot;\u300d\u306fC\u30c9\u30e9\u30a4\u30d6\u306b\u3042\u308btemp\u30d5\u30a9\u30eb\u30c0\u306etemp1.txt\u3068\u3044\u3046\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3068\u3044\u3046\u610f\u5473\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u306f\u3001\u4ee5\u4e0b\u306e\u4e00\u6587\u3067\u3059\u3002<br \/>\n\u8907\u6570\u884c\u66f8\u304b\u308c\u3066\u3044\u308b\u30d5\u30a1\u30a4\u30eb\u304b\u30891\u884c\u305a\u3064readLine\u30e1\u30bd\u30c3\u30c9\u3067\u8aad\u307f\u8fbc\u307f\u306a\u304c\u3089\u3001str\u5909\u6570\u306b\u4ee3\u5165\u3057\u3001\u305d\u306estr\u5909\u6570\u304cnull\u306b\u306a\u308b\u307e\u3067\uff08\u8aad\u307f\u8fbc\u3080\u30c7\u30fc\u30bf\u304c\u306a\u304f\u306a\u308b\u307e\u3067\uff09\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u8907\u6570\u884c\u6587\u5b57\u304c\u8a18\u8ff0\u3055\u308c\u3066\u308b\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u7e70\u308a\u8fd4\u3057\u51e6\u7406\r\nwhile ((str = br.readLine()) != null) {<\/code><\/pre>\n<p>\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30ed\u30fc\u30ba\u306f\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306e\u6587\u5b57\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u51e6\u7406\u306e\u8aac\u660e\u306f\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-4-2\"><span class=\"Num\">4.2.<\/span>\u30c7\u30fc\u30bf\u306e\u51fa\u529b<\/h4>\n<p>\u6b21\u306b\u3001\u6587\u5b57\u30c7\u30fc\u30bf\u306e\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f\u51e6\u7406\u3092\u5b66\u7fd2\u3057\u307e\u3059\u3002<br \/>\n\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f\u306b\u306fFileWriter\u30af\u30e9\u30b9\u3068BufferedWriter\u30af\u30e9\u30b9\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u304c\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u3059\u3002\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u6587\u5b57\u5217\u3092\u5165\u529b\u3057\u3001\u5165\u529b\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092C:\\temp\\temp2.txt\u306b\u66f8\u304d\u8fbc\u3093\u3067\u3044\u307e\u3059\u3002<br \/>\n\u66f8\u304d\u8fbc\u307f\u51e6\u7406\u306e\u3068\u304d\u306f\u3001\u8a72\u5f53\u30d5\u30a1\u30a4\u30eb\u304c\u5b58\u5728\u3057\u306a\u3044\u5834\u5408\u3001\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u65b0\u898f\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTest3.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOTest3 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\"\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3057\u305f\u5185\u5bb9\u3092temp2.txt\u306b\u66f8\u304d\u8fbc\u307f\u307e\u3059\");\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ \u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3092\u53d6\u5f97\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\tString str = \"\";\r\n\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt; \");\r\n\t\t\tstr = br.readLine();\r\n\r\n\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\u3002\r\n\t\t\tbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\temp2.txt\"));\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u3057\u307e\u3059\r\n\t\t\tbw.write(str);\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch(IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6587\u5b57\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u300c\u3053\u306e\u5f8c\u306b\u5165\u529b&gt;\u300d\u306e\u5f8c\u306b\u4f55\u304b\u6587\u5b57\u3092\u5165\u529b\u3057\u3066\u3001\u300cEnter\u300d\u30ad\u30fc\u3092\u62bc\u4e0b\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u305d\u306e\u6587\u5b57\u5217\u304c\u66f8\u304d\u8fbc\u307e\u308c\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">\u56f32 \u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u51fa\u529b\u5185\u5bb9<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3057\u305f\u5185\u5bb9\u3092temp2.txt\u306b\u66f8\u304d\u8fbc\u307f\u307e\u3059\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n\u30fb\u30fb\u4f55\u304b\u5165\u529b\u3059\u308b\u3068\u305d\u308c\u304c\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u8ff0\u3055\u308c\u307e\u3059<\/code><\/pre>\n<p>\u66f8\u304d\u8fbc\u307f\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u751f\u6210\u306f\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>BufferedWriter bw = null;\r\n\r\n\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\u3002\r\nbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\temp2.txt\"));<\/code><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f\u306f\u3001write\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u3057\u307e\u3059\r\nbw.write(str);<\/code><\/pre>\n<p>\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30ed\u30fc\u30ba\u306f\u3001\u5165\u529b\u51e6\u7406\u306e\u3068\u304d\u3068\u540c\u69d8\u3067\u3059\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u307e\u3059\r\nbw.close();<\/code><\/pre>\n<p>\u305f\u3060\u3057\u3001\u51fa\u529b\u51e6\u7406\u306e\u5834\u5408\u3001\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u5fd8\u308c\u308b\u3068\u30d0\u30c3\u30d5\u30a1\u30ea\u30f3\u30b0\u3055\u308c\u305f\u5024\u304c\u30d5\u30e9\u30c3\u30b7\u30e5\u3055\u308c\u305a\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3055\u308c\u307e\u305b\u3093\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001write\u30e1\u30bd\u30c3\u30c9\u3067\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3082\u3001close\u30e1\u30bd\u30c3\u30c9\u306e\u547c\u3073\u51fa\u3057\u3092\u5fd8\u308c\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u305f\u306e\u306b\u771f\u3063\u767d\u3001\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u304b\u306d\u307e\u305b\u3093\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h5 class=\"Heading Title Title--xs\" id=\"Bookmark-4-2-1\"><span class=\"Num\">4.2.1.<\/span>\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f<\/h5>\n<p>\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u66f8\u304d\u8fbc\u307f\u51e6\u7406\u3067\u4f7f\u3046FileWriter\u30af\u30e9\u30b9\u306f\u3001\u6a19\u6e96\u304c\u4e0a\u66f8\u304d\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u3064\u307e\u308a2\u884c\u4ee5\u4e0a\u306e\u6587\u5b57\u5217\u3092\u8a18\u8ff0\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u30011\u884c\u76ee\u304c2\u884c\u76ee\u306e\u6587\u5b57\u306b\u3088\u3063\u3066\u4e0a\u66f8\u304d\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u901a\u5e38\u306f\u3001\u8907\u6570\u884c\u306e\u30c7\u30fc\u30bf\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u8ffd\u52a0\u3067\u66f8\u304d\u8fbc\u307f\u3092\u3057\u307e\u3059\u306e\u3067\u3001\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f\u51e6\u7406\u306b\u3064\u3044\u3066\u3082\u5b66\u7fd2\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001new FileWriter(file\u540d\u3001true)\u3068\u3044\u3046\u3088\u3046\u306b\u3001File Writer\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u300ctrue\u300d\u3092\u7b2c2\u5f15\u6570\u3068\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u304c\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u3067\u3059\u3002\u5148\u307b\u3069\u306e\u66f8\u304d\u8fbc\u307f\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u300ctrue\u300d\u3092\u8ffd\u52a0\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<div class=\"Pre-title\">IOTest4.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOTest4 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\"\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u5165\u529b\u3057\u305f\u5185\u5bb9\u3092temp3.txt\u306b\u66f8\u304d\u8fbc\u3080\");\r\n\t\tSystem.out.println(\" \u300c!\u300d\uff0b Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\r\n\t\ttry {\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\t\/\/ FileWriter() \u306e\u5f15\u6570\u306b true \u3092\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f\u3068\u306a\u308a\u307e\u3059\r\n\t\t\tbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\temp3.txt\", true));\r\n\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\twhile (!str.equals(\"!\")) {\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt; \");\r\n\r\n\t\t\t\tstr = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\r\n\t\t\t\tbw.write(str);\r\n\r\n\t\t\t\t\/\/ \u6539\u884c\r\n\t\t\t\tbw.newLine();\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u901a\u5e38\u306f\u3001\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f\u3068\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u300ctrue\u300d\u3092\u3064\u3051\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u6587\u5b57\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b\u51e6\u7406\u306f\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-5\"><span class=\"Num\">5.<\/span>try-with-resources\u6587<\/h3>\n<p>\u3053\u3053\u307e\u3067\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u3084\u30d5\u30a1\u30a4\u30eb\u3068\u306e\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n\u305d\u3057\u3066\u3001\u305d\u308c\u3089\u306e\u4e00\u9023\u306e\u51e6\u7406\u306e\u6700\u5f8c\u306b\u306f\u3001\u5fc5\u305afinally\u53e5\u306b\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3068\u8aac\u660e\u3092\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u6bce\u56de\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b\u3053\u3068\u306f\u5197\u9577\u7684\u3067\u3042\u308a\u3001\u5197\u9577\u7684\u3067\u3042\u308b\u304c\u6545\u306b\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u306e\u3057\u5fd8\u308c\u306a\u3069\u304c\u8d77\u3053\u308a\u3084\u3059\u304f\u3001\u30d0\u30b0\u306e\u6e29\u5e8a\u306b\u306a\u308a\u3084\u3059\u3044\u3068\u3044\u3046\u554f\u984c\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001Java 7\u3088\u308atry-with-resources\u6587\u3068\u3044\u3046\u69cb\u6587\u304c\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-5-1\"><span class=\"Num\">5.1.<\/span>try-with-resources\u6587\u3068\u306f<\/h4>\n<p>\u4f8b\u5916\u51e6\u7406\u306e\u7ae0\u3067\u65e2\u306b\u5b66\u7fd2\u6e08\u307f\u306e\u3001try-catch-finally\u53e5\u306e\u69cb\u6587\u306e\u4e00\u3064\u3067\u3001\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u7701\u7565\u3057\u3066\u3082\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u89e3\u653e\u3092\u81ea\u52d5\u7684\u306b\u884c\u3063\u3066\u304f\u308c\u308b\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u300c4.1.1 \u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u6587\u5b57\u8aad\u307f\u8fbc\u307f\u300d\u306e\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u300cIOTest1.java\u300d\u3092\u3001try-with-resources\u6587\u3092\u4f7f\u3063\u3066\u66f8\u304d\u63db\u3048\u305f\u4f8b\u304c\u3001\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTest5.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOTest5 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\" \u300c!\u300d\uff0b Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\t\/\/ try\u306e\u3042\u3068\u306b()\u3092\u4ed8\u3051\u3066\u3001\u305d\u306e\u4e2d\u3067\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\ttry (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {\r\n\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\t\/\/ ! \u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u5165\u529b\u3059\u308b\u307e\u3067\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\r\n\t\t\twhile (!str.equals(\"!\")) {\r\n\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\");\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u8aad\u307f\u8fbc\u307f\u3001str\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\r\n\t\t\t\tstr = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\tSystem.out.println(\"\u5165\u529b\u3057\u305f\u5024\u306f\u300c\" + str + \"\u300d\u3067\u3059\u3002\");\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>try\u306e\u3042\u3068\u306b()\u3092\u4ed8\u52a0\u3057\u3066\u3001\u305d\u306e\u4e2d\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u751f\u6210\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001finally\u53e5\u304c\u306a\u304f\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u306b\u7740\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u3053\u308c\u306b\u3088\u308a\u3001finally\u53e5\u3067\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u306a\u304f\u3066\u3082\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u89e3\u653e\u304c\u81ea\u52d5\u7684\u306b\u884c\u308f\u308c\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001Java 9\u3088\u308a\u3001\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u3088\u3046\u306a\u66f8\u304d\u65b9\u3082\u53ef\u80fd\u306b\u306a\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTest6.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOTest6 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSystem.out.println(\" \u300c!\u300d\uff0b Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\t\/\/ \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\/\/ try\u306e\u3042\u3068\u306e()\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5909\u6570\u3092\u8a18\u8ff0\u3057\u307e\u3059\r\n\t\ttry (br) {\r\n\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\t\/\/ ! \u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u5165\u529b\u3059\u308b\u307e\u3067\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\r\n\t\t\twhile (!str.equals(\"!\")) {\r\n\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\");\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u8aad\u307f\u8fbc\u307f\u3001str\u5909\u6570\u306b\u4ee3\u5165\u3057\u3066\u3044\u307e\u3059\r\n\t\t\t\tstr = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3057\u305f\u5024\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\tSystem.out.println(\"\u5165\u529b\u3057\u305f\u5024\u306f\u300c\" + str + \"\u300d\u3067\u3059\u3002\");\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u30b9\u30c8\u30ea\u30fc\u30e0\u751f\u6210\u51e6\u7406\u3092try\u306e\u524d\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u3001\u305d\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092try\u306e\u3042\u3068\u306e()\u5185\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3053\u306e\u3088\u3046\u306a\u8a18\u6cd5\u3082\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3092\u62bc\u3055\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u306a\u304a\u3001\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u307e\u3067\u306e\u4e00\u9023\u306e\u6d41\u308c\u3092\u3057\u3063\u304b\u308a\u3068\u7406\u89e3\u3057\u3066\u3082\u3089\u3046\u305f\u3081\u306b\u3001\u3053\u306e\u6559\u6750\u3067\u306f\u4ee5\u964d\u3082try-with-resources\u6587\u3092\u4f7f\u308f\u306a\u3044\u66f8\u304d\u65b9\u3067\u89e3\u8aac\u3092\u884c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>try-with-resources\u6587\u306e\u8aac\u660e\u306f\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-6\"><span class=\"Num\">6.<\/span>Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u30fbFiles\u30af\u30e9\u30b9<\/h3>\n<p>\u307e\u305f\u3001Java7\u4ee5\u964d\u3067\u306fFile\u30af\u30e9\u30b9\u306b\u4ee3\u308f\u3063\u3066\u3001Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3084Files\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n\u3053\u308c\u306b\u3088\u308a\u3001\u30bd\u30fc\u30b9\u306e\u8a18\u8ff0\u3092\u7c21\u7565\u5316\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n\u4f8b\u3068\u3057\u3066\u3001\u30b3\u30d4\u30fc\u51e6\u7406\u3092\u53d6\u308a\u4e0a\u3052\u307e\u3059\u3002<br \/>\nJava6\u4ee5\u524d\u3067\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001\u3042\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4fdd\u5b58\u3059\u308b\u5834\u5408\u306b\u306f\u81ea\u524d\u3067\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u5b66\u7fd2\u3057\u305f\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u7528\u3044\u305f\u66f8\u304d\u65b9\u3067\u3059\u3002<\/p>\n<div class=\"Pre-title\">IOTestCopy.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.FileReader;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\n\r\npublic class IOTestCopy {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbr = new BufferedReader(new FileReader(\"C:\\\\temp\\\\temp1.txt\"));\r\n\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\temp2.txt\"));\r\n\t\t\tString str = null;\r\n\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u8907\u6570\u884c\u6587\u5b57\u304c\u8a18\u8ff0\u3055\u308c\u3066\u308b\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u7e70\u308a\u8fd4\u3057\u51e6\u7406\r\n\t\t\twhile ((str = br.readLine()) != null) {\r\n\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u3057\u307e\u3059\r\n\t\t\t\tbw.write(str);\r\n\t\t\t\tbw.newLine();\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u305d\u308c\u3067\u306fPath\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u7528\u3044\u305f\u51e6\u7406\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u5909\u6570\u300cbr\u300d\u304a\u3088\u3073\u300cbw\u300d\u3078\u306e\u4ee3\u5165\u306e\u4ed5\u65b9\u304c\u5148\u307b\u3069\u306e\u51e6\u7406\u3068\u7570\u306a\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"Pre-title\">IOTestCopy2.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.IOException;\r\nimport java.nio.file.Files;\r\nimport java.nio.file.Path;\r\nimport java.nio.file.Paths;\r\n\r\npublic class IOTestCopy2 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\t\tPath inputPath = Paths.get(\"C:\\\\temp\\\\temp1.txt\");\r\n\t\tPath outputPath = Paths.get(\"C:\\\\temp\\\\temp21.txt\");\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u3066\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbr = Files.newBufferedReader(inputPath);\r\n\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\u3057\u307e\u3059\r\n\t\t\tbw = Files.newBufferedWriter(outputPath);\r\n\r\n\t\t\tString str = null;\r\n\r\n\t\t\t\/\/ \u30d5\u30a1\u30a4\u30eb\u306b\u306f\u8907\u6570\u884c\u6587\u5b57\u304c\u8a18\u8ff0\u3055\u308c\u3066\u308b\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u7e70\u308a\u8fd4\u3057\u51e6\u7406\r\n\t\t\twhile ((str = br.readLine()) != null) {\r\n\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u3057\u307e\u3059\r\n\t\t\t\tbw.write(str);\r\n\t\t\t\tbw.newLine();\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\u6700\u5f8c\u306bFiles\u30af\u30e9\u30b9\u306e\u30b3\u30d4\u30fc\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u3044\u305f\u30b3\u30d4\u30fc\u51e6\u7406\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<br \/>\n\u3055\u304d\u307b\u3069\u306e\u51e6\u7406\u3067\u306f\u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3067\u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab\u304c\u306a\u304f\u306a\u308b\u307e\u3067\u51fa\u529b\u51e6\u7406\u3092\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001<br \/>\nFiles\u30af\u30e9\u30b9\u306eCopy\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u8a18\u8ff0\u91cf\u304c\u683c\u6bb5\u306b\u5c11\u306a\u304f\u306a\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"Pre-title\">IOTestCopy3.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.IOException;\r\nimport java.nio.file.Files;\r\nimport java.nio.file.Path;\r\nimport java.nio.file.Paths;\r\nimport java.nio.file.StandardCopyOption;\r\n\r\npublic class IOTestCopy3 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tPath inputPath = Paths.get(\"C:\/temp\/temp1.txt\");\r\n\t\tPath outputPath = Paths.get(\"C:\/temp\/temp2.txt\");\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ iputPath\u5909\u6570\u306e\u5185\u5bb9\u3092outPath\u5909\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u3078\u30b3\u30d4\u30fc\u3057\u307e\u3059\r\n\t\t\tFiles.copy(inputPath, outputPath, StandardCopyOption.REPLACE_EXISTING);\r\n\t\t} catch (IOException e) {\r\n\t\t\t\/\/ \u4f8b\u5916\u5185\u5bb9\u3092\u8868\u793a\u3057\u307e\u3059\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3068Files\u30af\u30e9\u30b9\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u30bd\u30fc\u30b9\u306e\u8a18\u8ff0\u5185\u5bb9\u304c\u7c21\u7565\u5316\u3055\u308c\u305f\u3053\u3068\u3092\u78ba\u8a8d\u3067\u304d\u305f\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/nio\/file\/Path.html\"\n\tclass=\"Ext Post-link\">Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<\/a>\u3084<a\n\thref=\"https:\/\/docs.oracle.com\/javase\/jp\/11\/docs\/api\/java.base\/java\/nio\/file\/Files.html\"\n\tclass=\"Ext Post-link\">Files\u30af\u30e9\u30b9<\/a>\u306b\u306f\u3053\u3053\u3067\u7d39\u4ecb\u3057\u305f\u4ee5\u5916\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u307e\u3060\u307e\u3060\u3042\u308a\u307e\u3059\u3002<br \/>\n\u8a73\u7d30\u306f\u30ea\u30f3\u30af\u5148\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"Information-block\">\n<div class=\"Information-heading\">\n<div class=\"Google-icon Google-icon--information\"><\/div>\n<div class=\"Information-heading__child\">Information<\/div>\n<\/p><\/div>\n<p>\tPath\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3067\u306f\u69d8\u3005\u306a\u30d1\u30b9\u306e\u8868\u73fe\u65b9\u6cd5\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<br \/>\n\t\u4eca\u307e\u3067File\u30af\u30e9\u30b9\u3067\u53d6\u5f97\u3057\u3066\u3044\u305f\u30d1\u30b9\u3067\u3059\u304c\u3001Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30d1\u30b9\u306e\u8a18\u8ff0\u306e\u81ea\u7531\u5ea6\u304c\u4e0a\u304c\u308a\u307e\u3057\u305f\u3002<br \/>\n\t\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306e\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3066\u3001\u5b9f\u969b\u306b\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"Pre-title\">PathTest.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.nio.file.Path;\r\nimport java.nio.file.Paths;\r\n\r\npublic class PathTest {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tPath pathA = Paths.get(\"C:\/temp\/sample2.txt\");\r\n\t\tPath pathB = Paths.get(\"C:\/temp\", \"sample2.txt\");\r\n\t\tPath pathC = Paths.get(\"C:\", \"temp\", \"sample2.txt\");\r\n\r\n\t\tif (pathA.equals(pathB) &amp;&amp; pathA.equals(pathC)) {\r\n\t\t\tSystem.out.println(\"pathA\u3068pathB\u3068pathC\u306f\u540c\u5024\u3067\u3059\u3002\");\r\n\t\t} else {\r\n\t\t\tSystem.out.println(\"pathA\u3068pathB\u3068pathC\u306f\u540c\u5024\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\");\r\n\t\t}\r\n\r\n\t\t\/\/ \u51fa\u529b\u7d50\u679c\u300cpathA\u3068pathB\u3068pathC\u306f\u540c\u5024\u3067\u3059\u3002\u300d\r\n\r\n\t}\r\n}<\/code><\/pre>\n<\/div>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-7\"><span class=\"Num\">7.<\/span>\u7df4\u7fd2\u554f\u984c1<\/h3>\n<p>\u305d\u308c\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u5165\u51fa\u529b\u306e\u7df4\u7fd2\u554f\u984c\u3092\u884c\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-7-1\"><span class=\"Num\">7.1.<\/span>\u554f\u984c1<\/h4>\n<p>\u300cC:\\temp\\mondaitemp1.txt\u300d\u3092\u4f5c\u6210\u3057\u3001\u4ee5\u4e0b\u306e\u5185\u5bb9\u3092\u5165\u529b\u3057\u3066\u4fdd\u5b58\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"Copy prettyprint lang-js\"><code>Java\u306e\u5165\u51fa\u529b\u51e6\u7406\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3092\u4e2d\u5fc3\u306b\u8003\u3048\u308b\u3068\u826f\u3044\u3067\u3057\u3087\u3046\u3002\r\n\r\n\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u307b\u3068\u3093\u3069\u5b9a\u578b\u6587\u3067\u3059\u3002\r\n\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u306e\u6307\u5b9a\u3092\u9069\u5207\u306b\u884c\u3048\u3070\u3001\u6b63\u3057\u304f\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u3067\u3057\u3087\u3046\u3002<\/code><\/pre>\n<p>\u4fdd\u5b58\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u300cC:\\temp\\mondaikekka1.txt\u300d\u306b\u66f8\u304d\u8fbc\u3080\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u306a\u304a\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3059\u308b\u969b\u3001\u6587\u5b57\u30b3\u30fc\u30c9\u306f\u300c<span class=\"Text-highlight\">UTF-8<\/span>\u300d\u3067\u4fdd\u5b58\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u30e1\u30e2\u5e33\u3067\u3042\u308c\u3070\u3001\u4fdd\u5b58\u3059\u308b\u3068\u304d\u306b\u300c\u6587\u5b57\u30b3\u30fc\u30c9\u300d\u306e\u30d7\u30eb\u30c0\u30a6\u30f3\u304c\u4e0b\u306e\u65b9\u306b\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u305d\u3053\u3067\u300cUTF-8\u300d\u3092\u9078\u3079\u3070OK\u3067\u3059\u3002<\/p>\n<div class=\"Answer-block\">\n\t<input class=\"SW\" type=\"checkbox\" id=\"Answer-content-1\"><label for=\"Answer-content-1\" class=\"Answer-SW\"><span\n\t\t\tclass=\"Google-icon Google-icon--arrow-single-gray\"><\/span>\u89e3\u7b54\u3092\u8868\u793a\u3059\u308b<\/label><\/p>\n<div class=\"Answer-content\">\n<div class=\"Pre-title\">IOMondai1_1.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.FileReader;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\n\r\npublic class IOMondai1_1 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ mondaitemp1.txt\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\r\n\t\t\tbr = new BufferedReader(new FileReader(\"C:\\\\temp\\\\mondaitemp1.txt\"));\r\n\r\n\t\t\t\/\/ mondaikekka1.txt\u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u8fbc\u3080\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u751f\u6210\r\n\t\t\tbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\mondaikekka1.txt\", true));\r\n\r\n\t\t\t\/\/ \u6587\u5b57\u5217\u683c\u7d0d\u7528\u5909\u6570\u3092\u5ba3\u8a00\u3068\u521d\u671f\u5316\r\n\t\t\tString str = null;\r\n\r\n\t\t\t\/\/ 1\u884c\u305a\u3064\u30d5\u30a1\u30a4\u30eb\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\r\n\t\t\twhile ((str = br.readLine()) != null) {\r\n\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u3092mondaikekka1.txt\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\r\n\t\t\t\tbw.write(str);\r\n\t\t\t\t\/\/ \u6539\u884c\r\n\t\t\t\tbw.newLine();\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\t\t\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u306e\u6307\u5b9a\u3092\u9593\u9055\u3048\u306a\u3044\u3088\u3046\u306b\u6c17\u3092\u3064\u3051\u307e\u3057\u3087\u3046\u3002<br \/>\n\t\t\u307e\u305f\u3001\u66f8\u304d\u8fbc\u307f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30aa\u30fc\u30d7\u30f3\u3059\u308b\u3068\u304d\u306b\u3001\u300c\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f\u300d\u306e\u305f\u3081\u306e\u300ctrue\u300d\u5f15\u6570\u3067\u53d7\u3051\u6e21\u3059\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\t\t\u66f8\u304d\u8fbc\u307f\u51e6\u7406\u306f\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u5f8c\u3067\u306f\u3001\u8aad\u307f\u8fbc\u3093\u3060\u30c7\u30fc\u30bf\u304c\u6b8b\u3063\u3066\u3044\u307e\u305b\u3093\u306e\u3067\u3001\u8aad\u307f\u8fbc\u307f\u306e\u7e70\u308a\u8fd4\u3057\u306e\u51e6\u7406\u306e\u4e2d\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002\n\t<\/p><\/div>\n<\/div>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-8\"><span class=\"Num\">8.<\/span>\u7df4\u7fd2\u554f\u984c2<\/h3>\n<p>\u30b3\u30f3\u30bd\u30fc\u30eb\u304b\u3089\u306e\u5165\u529b\u3068\u30d5\u30a1\u30a4\u30eb\u51fa\u529b\u306e\u7df4\u7fd2\u554f\u984c\u3067\u3059\u3002<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-8-1\"><span class=\"Num\">8.1.<\/span>\u554f\u984c1<\/h4>\n<p>\u4ee5\u4e0b\u306e\u5b9f\u884c\u7d50\u679c\u306e\u3088\u3046\u306b\u3001\u300c\u308a\u3093\u3054\u300d\u3001\u300c\u30d0\u30ca\u30ca\u300d\u3001\u300c\u306a\u3057\u300d\u3001\u300c\u3082\u3082\u300d\u3092\u9806\u756a\u306b\u5165\u529b\u3057\u307e\u3059\u3002<br \/>\n\u5165\u529b\u3055\u308c\u305f\u5024\u30924\u3064\u306e\u8981\u7d20\u3092\u6301\u3064\u6587\u5b57\u5217\u578b\u914d\u5217\u306b\u683c\u7d0d\u3057\u3001\u683c\u7d0d\u3057\u305f\u914d\u5217\u306e\u8981\u7d20\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u306a\u304a\u3001\u300c!\u300d\u3092\u5165\u529b\u3057\u305f\u5834\u5408\u306f\u305d\u306e\u6642\u70b9\u3067\u7d42\u4e86\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u3068\u304d\u3001\u300c!\u300d\u306f\u914d\u5217\u306b\u683c\u7d0d\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u307e\u305f\u3001\u6587\u5b57\u5217\u578b\u914d\u5217\u306f4\u3064\u306e\u8981\u7d20\u3057\u304b\u5165\u3089\u306a\u3044\u305f\u3081\u30014\u56de\u5024\u3092\u5165\u529b\u3055\u308c\u305f\u5834\u5408\u3082\u51e6\u7406\u3092\u7d42\u4e86\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<span class=\"Text-highlight\">\u203b \u30d2\u30f3\u30c8\uff1a<\/span><br \/>\n1. \u30b3\u30f3\u30bd\u30fc\u30eb\u3078\u306e\u5165\u529b\u53d7\u4ed8\u3092\u7e70\u308a\u8fd4\u3057\uff08while\u6587\u307e\u305f\u306ffor\u6587\uff09\u884c\u3046\u969b\u3001\u6761\u4ef6\u5f0f\u306b4\u56de\u307e\u3067\u3057\u304b\u7e70\u308a\u8fd4\u3055\u306a\u3044\u3088\u3046\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n2. \u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u305f\u5834\u5408\u306b\u7d42\u4e86\u3059\u308b\u51e6\u7406\u306f\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u306e\u4e2d\u3067\u3001\u6761\u4ef6\u5206\u5c90\u3067\u5224\u5b9a\u3057\u3001\u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u305f\u3089break\u3057\u3066\u3001\u5f37\u5236\u7684\u306b\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3092\u629c\u3051\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"Pre-title\">\u56f35 \u5b9f\u884c\u7d50\u679c<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>\u300c!\u300d \uff0b Enter\u3067\u7d42\u4e86\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n\u308a\u3093\u3054\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n\u30d0\u30ca\u30ca\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n\u306a\u3057\r\n\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\r\n\u3082\u3082\r\n\u308a\u3093\u3054\r\n\u30d0\u30ca\u30ca\r\n\u306a\u3057\r\n\u3082\u3082<\/code><\/pre>\n<div class=\"Answer-block\">\n\t<input class=\"SW\" type=\"checkbox\" id=\"Answer-content-2\"><label for=\"Answer-content-2\" class=\"Answer-SW\"><span\n\t\t\tclass=\"Google-icon Google-icon--arrow-single-gray\"><\/span>\u89e3\u7b54\u3092\u8868\u793a\u3059\u308b<\/label><\/p>\n<div class=\"Answer-content\">\n<div class=\"Pre-title\">IOMondai2_1.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class IOMondai2_1 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\t\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u51fa\u529b\r\n\t\tSystem.out.println(\"\u300c!\u300d + Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\tBufferedReader br = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ 4\u3064\u306e\u8981\u7d20\u3092\u6301\u3064\u6587\u5b57\u5217\u578b\u914d\u5217\u306e\u5b9a\u7fa9\r\n\t\t\tString[] fruit = new String[4];\r\n\r\n\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u5024\u3092\u683c\u7d0d\u3059\u308b\u5909\u6570\u5b9a\u7fa9\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\t\/\/ \u914d\u5217\u306e\u6dfb\u3048\u5b57\u7528\u5909\u6570\u5b9a\u7fa9\r\n\t\t\tint i = 0;\r\n\r\n\t\t\t\/\/ \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u751f\u6210\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\t\/\/ \u6587\u5b57\u5217\u578b\u914d\u5217\u306e\u6570\u307e\u3067\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u3092\u7e70\u308a\u8fd4\u3057\r\n\t\t\twhile (i &lt; fruit.length) {\r\n\t\t\t\t\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u51fa\u529b\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\");\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3055\u308c\u305f\u5024\u3092\u5909\u6570\u306b\u683c\u7d0d\r\n\t\t\t\tstr  = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u305f\u5834\u5408\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3092\u7d42\u4e86\r\n\t\t\t\tif(str.equals(\"!\")) {\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\t\/\/ \u5165\u529b\u3055\u308c\u305f\u5024\u3092\u914d\u5217\u306b\u683c\u7d0d\r\n\t\t\t\tfruit[i] = str;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\r\n\t\t\t\/\/ \u914d\u5217\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3057\u30b3\u30f3\u30bd\u30fc\u30eb\u51fa\u529b\r\n\t\t\tfor (i = 0; i &lt; fruit.length; i++) {\r\n\t\t\t\tif (fruit[i] != null) {\r\n\t\t\t\t\t\/\/ \u51fa\u529b\r\n\t\t\t\t\tSystem.out.println(fruit[i]);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\t\t\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u308b\u307e\u3067\u3001\u5165\u529b\u51e6\u7406\u3092\u7d9a\u3051\u308b\u306b\u306f\u3001\u300cstr.equals(&quot;!&quot;)\u300d\u3067\u5224\u5b9a\u3067\u304d\u307e\u3059\u3002<br \/>\n\t\t\u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u305f\u5834\u5408\u3001break\u3067\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3092\u629c\u3051\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\t\t\u4e00\u901a\u308a\u306e\u51e6\u7406\u304c\u7d42\u4e86\u3057\u305f\u3089\u3001\u6700\u5f8c\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3059\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\n\t<\/p><\/div>\n<\/div>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-8-2\"><span class=\"Num\">8.2.<\/span>\u554f\u984c2<\/h4>\n<p>\u554f\u984c1\u3067\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u53c2\u8003\u306b\u3057\u3066\u3001\u300c\u308a\u3093\u3054\u300d\u3001\u300c\u30d0\u30ca\u30ca\u300d\u3001\u300c\u306a\u3057\u300d\u3001\u300c\u3082\u3082\u300d\u3092\u683c\u7d0d\u3057\u305f\u9806\u756a\u3068\u306f\u9006\u306e\u9806\u756a\u3067\u914d\u5217\u304b\u3089\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3057\u3066\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><span class=\"Text-highlight\">\u203b\u3053\u306e\u554f\u984c\u306e\u89e3\u7b54\u306f\u63b2\u8f09\u3057\u3066\u304a\u308a\u307e\u305b\u3093\u3002<span class=\"Post-link\" >Tech Fun IT\u30b9\u30af\u30fc\u30eb\u306eJava\u7814\u4fee<\/span>\u3067\u306f\u3001\u8b1b\u5e2b\u304c\u4e01\u5be7\u306b\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/span><br \/>\n<span class=\"Text-red-bold\">\u73fe\u5728Tech Fun IT\u30b9\u30af\u30fc\u30eb\u3067\u306f\u3001\u65b0\u898f\u53d7\u8b1b\u8005\u306e\u52df\u96c6\u306f\u884c\u306a\u3063\u3066\u304a\u308a\u307e\u305b\u3093\u3002<\/span>\t\t<\/p>\n<h4 class=\"Heading Title Title--s\" id=\"Bookmark-8-3\"><span class=\"Num\">8.3.<\/span>\u554f\u984c3<\/h4>\n<p>\u554f\u984c1\u3001\u554f\u984c2\u3067\u4f5c\u6210\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u53c2\u8003\u306b\u3057\u3066\u3001\u300c\u308a\u3093\u3054\u300d\u3001\u300c\u30d0\u30ca\u30ca\u300d\u3001\u300c\u306a\u3057\u300d\u3001\u300c\u3082\u3082\u300d\u3092\u683c\u7d0d\u3057\u305f\u9806\u756a\u3068\u306f\u9006\u306e\u9806\u756a\u3067\u914d\u5217\u304b\u3089\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3057\u3066\u3001\u300cC:\\temp\\mondaikekka2.txt\u300d\u306b\u66f8\u304d\u8fbc\u3080\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"Answer-block\">\n\t<input class=\"SW\" type=\"checkbox\" id=\"Answer-content-3\"><label for=\"Answer-content-3\" class=\"Answer-SW\"><span\n\t\t\tclass=\"Google-icon Google-icon--arrow-single-gray\"><\/span>\u89e3\u7b54\u3092\u8868\u793a\u3059\u308b<\/label><\/p>\n<div class=\"Answer-content\">\n<div class=\"Pre-title\">IOMondai2_3.java<\/div>\n<pre class=\"Copy prettyprint lang-js\"><code>import java.io.BufferedReader;\r\nimport java.io.BufferedWriter;\r\nimport java.io.InputStreamReader;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;\r\n\r\npublic class IOMondai2_3 {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\t\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u51fa\u529b\r\n\t\tSystem.out.println(\"\u300c!\u300d + Enter\u3067\u7d42\u4e86\");\r\n\r\n\t\tBufferedReader br = null;\r\n\t\tBufferedWriter bw = null;\r\n\r\n\t\ttry {\r\n\t\t\t\/\/ 4\u3064\u306e\u8981\u7d20\u3092\u6301\u3064\u6587\u5b57\u5217\u578b\u914d\u5217\u306e\u5b9a\u7fa9\r\n\t\t\tString[] fruit = new String[4];\r\n\r\n\t\t\t\/\/ \u8aad\u307f\u8fbc\u3093\u3060\u5024\u3092\u683c\u7d0d\u3059\u308b\u5909\u6570\u5b9a\u7fa9\r\n\t\t\tString str = \"\";\r\n\r\n\t\t\t\/\/ \u914d\u5217\u306e\u6dfb\u3048\u5b57\u7528\u5909\u6570\u5b9a\u7fa9\r\n\t\t\tint i = 0;\r\n\r\n\t\t\t\/\/ \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u751f\u6210\r\n\t\t\tbr = new BufferedReader(new InputStreamReader(System.in));\r\n\r\n\t\t\t\/\/ \u6587\u5b57\u5217\u578b\u914d\u5217\u306e\u6570\u307e\u3067\u3001\u5165\u529b\u5f85\u6a5f\u72b6\u614b\u3092\u7e70\u308a\u8fd4\u3057\r\n\t\t\twhile (i &lt; fruit.length) {\r\n\t\t\t\t\/\/ \u30e1\u30c3\u30bb\u30fc\u30b8\u51fa\u529b\r\n\t\t\t\tSystem.out.println(\"\u3053\u306e\u5f8c\u306b\u5165\u529b &gt;\");\r\n\r\n\t\t\t\t\/\/ \u5165\u529b\u3055\u308c\u305f\u5024\u3092\u5909\u6570\u306b\u683c\u7d0d\r\n\t\t\t\tstr  = br.readLine();\r\n\r\n\t\t\t\t\/\/ \u300c!\u300d\u304c\u5165\u529b\u3055\u308c\u305f\u5834\u5408\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\u3092\u7d42\u4e86\r\n\t\t\t\tif (str.equals(\"!\")) {\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t\t\/\/ \u5165\u529b\u3055\u308c\u305f\u5024\u3092\u914d\u5217\u306b\u683c\u7d0d\r\n\t\t\t\tfruit[i] = str;\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\r\n\t\t\t\/\/ \u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u751f\u6210\r\n\t\t\tbw = new BufferedWriter(new FileWriter(\"C:\\\\temp\\\\mondaikekka2.txt\", true));\r\n\r\n\t\t\t\/\/ \u9006\u9806\u306b\u914d\u5217\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3057\u30d5\u30a1\u30a4\u30eb\u306b\u51fa\u529b\r\n\t\t\tfor (i = fruit.length - 1; i &gt;= 0; i--) {\r\n\t\t\t\tif (fruit[i] != null) {\r\n\t\t\t\t\t\/\/ \u51fa\u529b\r\n\t\t\t\t\tbw.write(fruit[i]);\r\n\r\n\t\t\t\t\t\/\/ \u6539\u884c\r\n\t\t\t\t\tbw.newLine();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\r\n\t\t} finally {\r\n\t\t\tif (br != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u8aad\u307f\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbr.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tif (bw != null) {\r\n\t\t\t\ttry {\r\n\t\t\t\t\t\/\/ \u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u30af\u30ed\u30fc\u30ba\u3057\u307e\u3059\r\n\t\t\t\t\tbw.close();\r\n\r\n\t\t\t\t} catch (IOException e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/code><\/pre>\n<p>\t\t\u66f8\u304d\u8fbc\u307f\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30ed\u30fc\u30ba\u3082\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\n\t<\/p><\/div>\n<\/div>\n<div class=\"Separator\">\n<div class=\"Separator__child\"><\/div>\n<\/div>\n<h3 class=\"Heading Title Title--m\" id=\"Bookmark-9\"><span class=\"Num\">9.<\/span>\u672c\u7ae0\u306e\u307e\u3068\u3081<\/h3>\n<ul class=\"Base-list\">\n<li class=\"Base-list__child\">\u5165\u529b\u7cfb\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u3068\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u300cFileReader\u300d\u3084\u30b3\u30f3\u30bd\u30fc\u30eb\u5165\u529b\u3092\u53d7\u3051\u53d6\u308b\u300cInputStreamReader\u300d\u306a\u3069\u304c\u3042\u308b\u3002<\/li>\n<li class=\"Base-list__child\">\u51fa\u529b\u7cfb\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u51fa\u529b\u3092\u884c\u3046\u300cFileWriter\u300d\u306a\u3069\u304c\u3042\u308b\u3002 <\/li>\n<li class=\"Base-list__child\">\u5165\u529b\/\u51fa\u529b\u3068\u3082\u306b\u3001\u51e6\u7406\u306e\u57fa\u672c\u7684\u306a\u6d41\u308c\u306f\u300c\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u958b\u304f\u2192\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u66f8\u304d\u3092\u884c\u3046\u2192\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u308b\u300d\u3067\u3042\u308b\u3002 <\/li>\n<li class=\"Base-list__child\">\u30b9\u30c8\u30ea\u30fc\u30e0\u306f\u5fc5\u305a\u9589\u3058\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u305f\u3081\u3001\u57fa\u672c\u7684\u306b\u306ftry-catch-finally\u6587\u3092\u4f7f\u7528\u3057\u3066\u3001finally\u53e5\u306e\u4e2d\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u66f8\u304b\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3002<\/li>\n<li class=\"Base-list__child\">\u4f8b\u5916\u51e6\u7406\u3092\u304d\u3061\u3093\u3068\u5b9f\u88c5\u3057\u306a\u3044\u3068\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3002<\/li>\n<li class=\"Base-list__child\">\u81ea\u52d5\u7684\u306b\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30af\u30ed\u30fc\u30ba\u51e6\u7406\u3092\u884c\u3046\u69cb\u6587\u3068\u3057\u3066\u300ctry-with-resources\u6587\u300d\u304c\u3042\u308b\u3002\n\t<\/li>\n<li class=\"Base-list__child\">File\u30af\u30e9\u30b9\u306e\u4ee3\u308f\u308a\u306b\u3001Path\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3084Files\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u3053\u3068\u3082\u51fa\u6765\u308b\u3002<\/li>\n<\/ul>\n<p>\u5165\u51fa\u529b\u306b\u95a2\u3059\u308b\u5b9f\u88c5\u306f\u3042\u308b\u7a0b\u5ea6\u6c7a\u307e\u3063\u305f\u5f62\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u305a\u306f\u4f55\u5ea6\u3082\u66f8\u3044\u3066\u899a\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u3064\u3044\u3066\u306e\u8aac\u660e\u306f\u3001\u4ee5\u4e0a\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u672c\u7ae0\u3067\u306e\u5b66\u7fd2\u9805\u76ee \u672c\u7ae0\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3093\u3060\u308a\u3059\u308b\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u95a2\u3057\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002 2.\u672c\u7ae0\u306e\u8b1b\u7fa9 \u672c\u7ae0\u3067\u5b66\u7fd2\u3059\u308b\u5185\u5bb9\u3092\u52d5\u753b\u3068\u3057\u3066\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3059\u3002\u6700\u521d\u306b\u4e00\u901a\u308a\u898b\u7d42\u308f\u3063\u305f\u5f8c\u3067\u2026<\/p>\n","protected":false},"author":5,"featured_media":6007,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"class_list":["post-187","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-base"],"acf":{"chapter":12,"javabase_order":14,"list-display_description":"\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u3093\u3060\u308a\u3059\u308b\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u95a2\u3057\u3066\u5b66\u7fd2\u3057\u307e\u3059\u3002"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":20,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":6500,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/posts\/187\/revisions\/6500"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/media\/6007"}],"wp:attachment":[{"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techfun.cc\/wp-json\/wp\/v2\/categories?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}