{"id":1116,"date":"2018-12-11T12:00:09","date_gmt":"2018-12-11T03:00:09","guid":{"rendered":"https:\/\/www.bold.ne.jp\/engineer-club\/?p=1116"},"modified":"2025-09-17T14:03:33","modified_gmt":"2025-09-17T05:03:33","slug":"java-file","status":"publish","type":"post","link":"https:\/\/www.bold.ne.jp\/engineer-club\/java-file","title":{"rendered":"java file\u3068\u306f\uff1fFile\u3068NIO.2\u3092\u4f7f\u3063\u305fJava\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c"},"content":{"rendered":"<p><strong>java.io.File\u306f\u3001Java\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea(=\u30d5\u30a9\u30eb\u30c0)\u306e\u64cd\u4f5c\u3092\u884c\u3048\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/strong>\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u3001\u524a\u9664\u3001\u5b58\u5728\u78ba\u8a8d\u306a\u3069\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u3067\u5fc5\u8981\u306a\u64cd\u4f5c\u3092\u4e00\u901a\u308a\u884c\u3048\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u4f7f\u3044\u65b9\u3092\u899a\u3048\u305f\u3044\u3082\u306e\u3067\u3059\u306d\u3002<\/p>\n<p>\u306a\u304a\u3001<span>Java 7<\/span>\u3067\u5c0e\u5165\u3055\u308c\u305f<span>More New I\/O APIs(NIO.2)<\/span>\u306b\u3088\u308a\u3001<span>File<\/span>\u306f\u516c\u5f0f\u306b\u306f\u904e\u53bb\u306e\u3082\u306e\u3068\u306a\u308a\u307e\u3057\u305f\u3002\u3067\u3082\u3001<span>File<\/span>\u306f\u4eca\u5f8c\u3082\u3042\u308a\u7d9a\u3051\u307e\u3059\u3057\u3001<span>File<\/span>\u3092\u4f7f\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u3084\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306f\u591a\u3044\u306e\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u73fe\u5834\u3067\u306f\u307e\u3060\u307e\u3060\u73fe\u5f79\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<span>File<\/span>\u3068<span>NIO.2<\/span>\u3092\u4f7f\u3063\u305f\u5404\u7a2e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c\u3092\u3056\u3063\u3068\u7d39\u4ecb\u3057\u307e\u3059\u3002\u53c2\u8003\u306b\u306a\u308b\u3082\u306e\u3082\u591a\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u8aad\u3093\u3067\u3044\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u203b\u3053\u306e\u8a18\u4e8b\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u3001<span>Java 10<\/span>\u306e\u74b0\u5883\u3067\u52d5\u4f5c\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#JavaFile\">\uff11\uff0e\u3010Java\u3011File\u306f\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u73fe\u3057\u305f\u3082\u306e<\/a><\/li><li><a href=\"#JavaFileNIO2\">\uff12\uff0e\u3010Java\u3011File\u3068NIO.2\u306b\u3088\u308b\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c\u306e\u4f8b<\/a><ul><li><a href=\"#i\">\uff12-\uff11\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b<\/a><\/li><li><a href=\"#i-2\">\uff12-\uff12\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b<\/a><\/li><li><a href=\"#i-3\">\uff12-\uff13\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30ea\u30cd\u30fc\u30e0\u3001\u30b3\u30d4\u30fc\u3059\u308b<\/a><\/li><li><a href=\"#i-4\">\uff12-\uff14\uff0e\u4e00\u89a7\u306e\u53d6\u5f97\u3001\u5b58\u5728\u306e\u78ba\u8a8d\u3001\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\u3059\u308b<\/a><\/li><li><a href=\"#i-5\">\uff12-\uff15\uff0e\u30d5\u30a1\u30a4\u30eb\u5165\u51fa\u529b\u3092\u3059\u308b<\/a><\/li><\/ul><\/li><li><a href=\"#More_New_IO_APIsNIO2\">\uff13\uff0e\u3010\u53c2\u8003\u3011More New I\/O APIs(NIO.2)\u306e\u767b\u5834<\/a><\/li><li><a href=\"#i-6\">\uff14\uff0e\u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"JavaFile\">\uff11\uff0e\u3010Java\u3011File\u306f\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u73fe\u3057\u305f\u3082\u306e<\/span><\/h2>\n<p>java.io.File\u306f\u3001<strong>\u4f55\u304b\u4e00\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3042\u308b\u3044\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea(=\u30d5\u30a9\u30eb\u30c0)\u3092\u8868\u73fe\u3057\u3066\u3044\u308b\u30af\u30e9\u30b9<\/strong>\u3067\u3059\u3002<span>Java<\/span>\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306f\u3053\u306e<span>File<\/span>\u3092\u901a\u3057\u3066\u884c\u3044\u307e\u3059\u306e\u3067\u3001\u5168\u3066\u306f<span>File<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3057\u305f\u308a\u53d6\u5f97\u3059\u308b\u3068\u3053\u308d\u304b\u3089\u59cb\u307e\u308a\u307e\u3059\u3002<\/p>\n<p>File\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u751f\u6210\u306e\u4ed5\u65b9\u306f\u7c21\u5358\u3067\u3001\u4ee5\u4e0b\u306e\u3044\u305a\u308c\u304b\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u4f7f\u3044\u307e\u3059\u3002\u4f55\u304b\u306e\u30d1\u30b9\u3092\u8868\u73fe\u3059\u308b<span>String<\/span>\u3092\u5f15\u6570\u306b\u53d6\u308b\u3082\u306e\u304c\u826f\u304f\u4f7f\u308f\u308c\u308b\u3082\u306e\u3067\u3057\u3087\u3046\u3002\u4ed6\u306b\u306f\u3001\u89aa\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u5225\u306e<span>File<\/span>\u3067\u6307\u5b9a\u3059\u308b\u3082\u306e\u3082\u826f\u304f\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ java.io.File\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\r\npublic File(String pathname)\r\n\tpathname - \u30d1\u30b9\u540d\u6587\u5b57\u5217\r\npublic File(String parent, String child)\r\n\tparent - \u89aa\u30d1\u30b9\u540d\u6587\u5b57\u5217\r\n\tchild - \u5b50\u30d1\u30b9\u540d\u6587\u5b57\u5217\r\npublic File(File parent, String child)\r\n\tparent - \u89aa\u62bd\u8c61\u30d1\u30b9\u540d\r\n\tchild - \u5b50\u30d1\u30b9\u540d\u6587\u5b57\u5217\r\npublic File(URI uri)\r\n\turi - \u968e\u5c64\u578b\u306e\u7d76\u5bfeURI\u3002<\/pre>\n<p>File\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u4f8b\u306f\u4ee5\u4e0b\u306e\u3082\u306e\u3067\u3059\u3002\u3061\u306a\u307f\u306b\u3001<span>File<\/span>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u751f\u6210\u3059\u308b\u6642\u306f\u3001\u5b9f\u969b\u306e<span>PC<\/span>\u30fb\u30b5\u30fc\u30d0\u4e0a\u306b\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u306a\u304f\u3066\u3082\u30a8\u30e9\u30fc\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u3002\u5fc5\u8981\u306a\u3060\u3051\u3069\u3093\u3069\u3093<span>new<\/span>\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file1 = new File(\"\/A\/B\/C.txt\"); \/\/ UNIX\u7cfbOS\u306e\u5834\u5408\r\nFile file2 = new File(\"C:\\\\A\\\\B\\\\C.txt\"); \/\/ Windows\u306e\u5834\u5408(\u5b9f\u969b\u306b\u306f\"\/\"\u3067\u3082\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093)\r\nFile dir = new File(\"\/A\/B\");\r\nFile file3 = new File(dir, \"D.csv\"); \/\/ \u2192 \/A\/B\/D.csv\u3092\u610f\u5473\u3059\u308bFile<\/pre>\n<h2><span id=\"JavaFileNIO2\">\uff12\uff0e\u3010Java\u3011File\u3068<span>NIO.2<\/span>\u306b\u3088\u308b\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c\u306e\u4f8b<\/span><\/h2>\n<p>\u3053\u3053\u3067\u306f\u3001<span>File<\/span>\u3092\u4f7f\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u64cd\u4f5c\u306e\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u3088\u304f\u4f7f\u3046\u3082\u306e\u3067\u3059\u3002\u53c2\u8003\u3068\u3057\u3066\u3001<span>Java 7<\/span>\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f<span>More New I\/O APIs(NIO.2)<\/span>\u3067\u306f\u3069\u306e\u3088\u3046\u306b\u306a\u308b\u304b\u3082\u4f75\u8a18\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u305d\u308c\u305e\u308c\u51e6\u7406\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306f<span>IOException<\/span>\u3092<span>throw<\/span>\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u9069\u5207\u306b<span>try-catch<\/span>\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3><span id=\"i\">\uff12-\uff11\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b<\/span><\/h3>\n<h4>\uff12-\uff11-\uff11\uff0e\u65b0\u898f\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b<span>(createNewFile)<\/span><\/h4>\n<p>File.createNewFile\u3092\u4f7f\u3046\u3068\u3001<span>File<\/span>\u304c\u8868\u73fe\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u65b0\u898f\u306b\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u4f5c\u6210\u3067\u304d\u305f\u304b\u3069\u3046\u304b\u306f\u623b\u308a\u5024\u306e<span>boolean<\/span>\u3067\u5224\u65ad\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nif (file.createNewFile()) {\r\n\tSystem.out.println(file.getAbsolutePath() + \"\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nFiles.createFile(file);<\/pre>\n<h4>\uff12-\uff11-\uff12\uff0e\u65b0\u898f\u306b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b<span>(mkdir\/mkdirs)<\/span><\/h4>\n<p>File.mkdir\u3042\u308b\u3044\u306f<span>mkdirs<\/span>\u3092\u4f7f\u3046\u3068\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<span>mkdir<\/span>\u306f\u30d1\u30b9\u306e\u4e00\u756a\u6700\u5f8c\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3060\u3051\u3092\u4f5c\u308a\u3001<span>mkdirs<\/span>\u306f\u30d1\u30b9\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4e2d\u3067\u5b58\u5728\u3057\u306a\u3044\u3082\u306e\u306f\u5168\u3066\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3067\u304d\u305f\u304b\u3069\u3046\u304b\u306f\u3001\u623b\u308a\u5024\u306e<span>boolean<\/span>\u3067\u5224\u65ad\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File dir = new File(\"\/A\/B\/C\");\r\ndir.mkdir(); \/\/ C\u3060\u3051\u4f5c\u6210\u3092\u8a66\u307f\u308b\r\n\/\/ dir.mkdirs(); \/\/ \u2192 \u4e2d\u9593\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea(\/A\/B)\u542b\u3081\u3066\u3001\u5168\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u4f5c\u6210\u3092\u8a66\u307f\u308b<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath dir = Paths.get(\"\/A\/B\/C\");\r\nFiles.createDirectory(dir);\r\n\/\/ Files.createDirectories(dir); \/\/ File.mkdirs\u3068\u540c\u3058\u52d5\u304d<\/pre>\n<h4>\uff12-\uff11-\uff13\uff0e\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b<\/h4>\n<p>File.createTempFile\u3092\u4f7f\u3046\u3068\u3001\u4e00\u6642\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u51e6\u7406\u5185\u3067\u4e00\u6642\u7684\u306b\u4f7f\u3044\u305f\u3044\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\u3053\u308c\u304c\u4f7f\u3048\u307e\u3059\u3002\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u524d\u5f8c\u306b\u4f55\u3092\u4ed8\u3051\u308b\u304b\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u5148\u3067\u30e1\u30bd\u30c3\u30c9\u304c\u9055\u3044\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u3001\u30b7\u30b9\u30c6\u30e0\u30d7\u30ed\u30d1\u30c6\u30a3<span>java.io.tmpdir<\/span>\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u5177\u4f53\u7684\u306b\u3069\u3053\u306b\u306a\u308b\u304b\u306f\u3001<span>OS<\/span>\u306b\u3088\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file1 = File.createTempFile(\"AAA\", \"ZZZ\"); \/\/ \u2192 \u30d5\u30a1\u30a4\u30ebAAA14772876267833857426ZZZ\u304c\u4f5c\u6210\u3055\u308c\u305f\r\nFile dir = new File(\"\/tmp\");\r\nFile file2 = File.createTempFile(\"AAA\", \"ZZZ\", dir); \/\/ \u4e00\u6642\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u547c\u3073\u51fa\u3057\u5074\u3067\u6307\u5b9a\u3059\u308b\u5834\u5408<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file1 = Files.createTempFile(\"AAA\", \"ZZZ\");\r\nPath dir = Paths.get(\"\/tmp\");\r\nPath file2 = Files.createTempFile(dir, \"AAA\", \"ZZZ\");<\/pre>\n<h3><span id=\"i-2\">\uff12-\uff12\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b<\/span><\/h3>\n<h4>\uff12-\uff12-\uff11\uff0e\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b<span>(delete)<\/span><\/h4>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u524a\u9664\u3059\u308b\u306b\u306f<span>File.delete<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002\u524a\u9664\u3067\u304d\u305f\u304b\u3069\u3046\u304b\u306f\u3001\u623b\u308a\u5024\u306e<span>boolean<\/span>\u3067\u5224\u65ad\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nif (file.delete()) {\r\n\tSystem.out.println(file.getAbsolutePath() + \"\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nFiles.delete(file);<\/pre>\n<h4>\uff12-\uff12-2\uff0e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b<span>(delete)<\/span><\/h4>\n<p>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3059\u308b\u5834\u5408\u3082<span>File.delete<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5185\u5bb9\u304c\u7a7a\u3067\u306a\u3051\u308c\u3070\u524a\u9664\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u4e8b\u524d\u306b\u30d5\u30a1\u30a4\u30eb\u3084\u30b5\u30d6\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u524a\u9664\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File dir = new File(\"\/A\/B\/C\");\r\nif (dir.delete()) {\r\n\tSystem.out.println(dir.getAbsolutePath() + \"\u3092\u524a\u9664\u3057\u307e\u3057\u305f\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath dir = Paths.get(\"\/A\/B\/C\");\r\nFiles.delete(dir);<\/pre>\n<h3><span id=\"i-3\">\uff12-\uff13\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30ea\u30cd\u30fc\u30e0\u3001\u30b3\u30d4\u30fc\u3059\u308b<\/span><\/h3>\n<h4>\uff12-\uff13-\uff11\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30ea\u30cd\u30fc\u30e0\u3059\u308b<span>(renameTo)<\/span><\/h4>\n<p>\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u30ea\u30cd\u30fc\u30e0\u3059\u308b\u306b\u306f\u3001\u5909\u66f4\u524d\u3068\u5909\u66f4\u5f8c\u306e\u4e8c\u3064\u306e<span>File<\/span>\u3092\u7528\u610f\u3057\u3001\u5909\u66f4\u524d\u306e<span>File<\/span>\u3067<span>File.renameTo<\/span>\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002\u30ea\u30cd\u30fc\u30e0\u306b\u6210\u529f\u3057\u305f\u304b\u306f\u3001\u623b\u308a\u5024\u306e<span>boolean<\/span>\u3067\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File from = new File(\"\/A\/B\/C.txt\");\r\nFile to = new File(\"\/A\/B\/D.txt\");\r\nif (from.renameTo(to)) {\r\n\tSystem.out.println(from.getAbsolutePath() + \"\u3092\" + to.getAbsolutePath() + \"\u3078\u30ea\u30cd\u30fc\u30e0\u3057\u307e\u3057\u305f\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath from = Paths.get(\"\/A\/B\/C.txt\");\r\nPath to = Paths.get(\"\/A\/B\/D.txt\");\r\nFiles.move(from, to);<\/pre>\n<h4>\uff12-\uff13-\uff12\uff0e\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b<\/h4>\n<p>File\u306b\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u306e\u305f\u3081\u3001\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u51e6\u7406\u3092\u81ea\u5206\u3067\u4f5c\u308b\u304b\u3001\u8272\u3005\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306a\u3069\u306b\u3042\u308b\u3082\u306e\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u4e00\u5ea6\u306b\u5168\u30c7\u30fc\u30bf\u3092\u30e1\u30e2\u30ea\u4e0a\u306b\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059\u306e\u3067\u3001\u975e\u5e38\u306b\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc\u306b\u306f\u5411\u3044\u3066\u3044\u307e\u305b\u3093\u3002\u305d\u306e\u5834\u5408\u306f\u30eb\u30fc\u30d7\u3092\u3057\u3066\u5c11\u3057\u305a\u3064\u8aad\u307f\u8fbc\u307f\u30fb\u66f8\u304d\u8fbc\u307f\u3092\u3059\u3079\u304d\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File from = new File(\"\/A\/B\/C.txt\");\r\nFile to = new File(\"\/A\/B\/D.txt\");\r\nbyte[] bytes = new byte[(int) from.length()];\r\n\r\ntry (FileInputStream fis = new FileInputStream(from);\r\n\t\tFileOutputStream fos = new FileOutputStream(to)) {\r\n\tfis.read(bytes);\r\n\tfos.write(bytes);\r\n}<\/pre>\n<p>\u3042\u308b\u3044\u306f\u3001<span>NIO<\/span>\u306e<span>Channel<\/span>\u3068\u547c\u3070\u308c\u308b\u30af\u30e9\u30b9\u3092\u4f7f\u3063\u3066\u30b3\u30d4\u30fc\u3092\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002\u3053\u3061\u3089\u306e\u65b9\u304c\u9ad8\u901f\u3067\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File from = new File(\"\/A\/B\/C.txt\");\r\nFile to = new File(\"\/A\/B\/D.txt\");\r\n\r\ntry (FileInputStream fis = new FileInputStream(from);\r\n\t\tFileOutputStream fos = new FileOutputStream(to);\r\n\t\tFileChannel fromCh = fis.getChannel();\r\n\t\tFileChannel toCh = fos.getChannel()) {\r\n\ttoCh.transferFrom(fromCh, 0, fromCh.size());\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath from = Paths.get(\"\/A\/B\/C.txt\");\r\nPath to = Paths.get(\"\/A\/B\/D.txt\");\r\nFiles.copy(from, to);<\/pre>\n<h3><span id=\"i-4\">\uff12-\uff14\uff0e\u4e00\u89a7\u306e\u53d6\u5f97\u3001\u5b58\u5728\u306e\u78ba\u8a8d\u3001\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\u3059\u308b<\/span><\/h3>\n<h4>\uff12-\uff14-\uff11\uff0e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u4e00\u89a7\u3092\u5f97\u308b<span>(listFiles)<\/span><\/h4>\n<p>File.listFiles\u3067\u306f\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u5185\u306e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5185\u5bb9\u3092<span>File<\/span>\u306e\u914d\u5217\u3067\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<span>String<\/span>\u3067\u826f\u3044\u306a\u3089\u3001<span>File.list<\/span>\u3067\u3082\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File dir = new File(\"\/A\/B\");\r\nFile[] entries = dir.listFiles();\r\nfor (File e : entries) {\r\n\tSystem.out.println(e.getAbsolutePath());\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath dir = Paths.get(\"\/A\/B\");\r\nList&lt;Path&gt; entries = Files.list(dir).collect(Collectors.toList()); \/\/ list\u3067\u306fStream&lt;Path&gt;\u304c\u623b\u308b\r\nfor (Path e : entries) {\r\n\tSystem.out.println(e.toAbsolutePath().toString());<\/pre>\n<h4>\uff12-\uff14-\uff12\uff0e\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u3092\u78ba\u8a8d\u3059\u308b<span>(exists)<\/span><\/h4>\n<p>\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u5b58\u5728\u78ba\u8a8d\u3092\u3057\u305f\u3044\u306a\u3089\u3001<span>File.exists<\/span>\u304c\u4f7f\u3048\u307e\u3059\u3002\u5b58\u5728\u3059\u308b\u5834\u5408\u306f<span>true<\/span>\u304c\u623b\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nif (file.exists()) {\r\n\tSystem.out.println(file.getAbsolutePath() + \"\u306f\u5b58\u5728\u3057\u307e\u3059\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nif (Files.exists(file)) {\r\n\tSystem.out.println(file.toAbsolutePath().toString() + \"\u306f\u5b58\u5728\u3057\u307e\u3059\u3002\");\r\n}<\/pre>\n<h4>\uff12-\uff14-\uff13\uff0eFile\u306e\u5b9f\u4f53\u304c\u4f55\u304b\u78ba\u8a8d\u3059\u308b<span>(isFile\/isDirectory)<\/span><\/h4>\n<p>File\u304c\u30d5\u30a1\u30a4\u30eb\u304b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304b\u5224\u65ad\u3059\u308b\u306b\u306f\u3001<span>File.isFile<\/span>\u3042\u308b\u3044\u306f<span>isDirectory<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nif (file.isFile()) {\r\n\tSystem.out.println(file.getAbsolutePath() + \"\u306f\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\");\r\n} else if (file.isDirectory()) {\r\n\tSystem.out.println(file.getAbsolutePath() + \"\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002\");\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nif (Files.isRegularFile(file)) {\r\n\tSystem.out.println(file.toAbsolutePath().toString() + \"\u306f\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002\");\r\n} else if (Files.isDirectory(file)) {\r\n\tSystem.out.println(file.toAbsolutePath().toString() + \"\u306f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u3059\u3002\");\r\n}<\/pre>\n<h4>\uff12-\uff14-\uff14\uff0e\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u53d6\u5f97\u3059\u308b<span>(length)<\/span><\/h4>\n<p>File.length\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u30b5\u30a4\u30ba\u3092<span>long<\/span>\u3067\u623b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nlong size = file.length();\r\nSystem.out.println(\"\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306f\" + size + \"\u30d0\u30a4\u30c8\u3067\u3059\u3002\");<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nlong size = Files.size(file);\r\nSystem.out.println(\"\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306f\" + size + \"\u30d0\u30a4\u30c8\u3067\u3059\u3002\");<\/pre>\n<h3><span id=\"i-5\">\uff12-\uff15\uff0e\u30d5\u30a1\u30a4\u30eb\u5165\u51fa\u529b\u3092\u3059\u308b<\/span><\/h3>\n<p>\u3053\u3053\u304b\u3089\u306f\u3001\u76f4\u63a5\u7684\u306a<span>File<\/span>\u306e\u4f7f\u3044\u65b9\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306b\u3064\u3044\u3066\u8a18\u8ff0\u3057\u307e\u3059\u3002\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u30fb\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3067\u3084\u308a\u65b9\u304c\u9055\u3044\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<h4>\uff12-\uff15-\uff11\uff0e\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u3059\u3079\u3066\u8aad\u307f\u8fbc\u3080<span>(<\/span>\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb<span>)<\/span><\/h4>\n<p>\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u6642\u306f\u3001<span>FileInputStream<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u306e\u4f8b\u3067\u306f<span>read<\/span>\u3067\u30d5\u30a1\u30a4\u30eb\u306e\u5168\u4f53\u3092<span>byte<\/span>\u914d\u5217\u3078\u4e00\u5ea6\u306b\u8aad\u307f\u8fbc\u3093\u3067\u3044\u307e\u3059\u3002\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u306f\u5206\u5272\u3057\u3066\u8aad\u307f\u8fbc\u3080\u306a\u3069\u3057\u3066\u3001<span>OutOfMemoryError<\/span>\u304c\u51fa\u306a\u3044\u3088\u3046\u306b\u5de5\u592b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.dat\");\r\ntry (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {\r\n\tbyte[] bytes = new byte[(int) file.length()];\r\n\tbis.read(bytes);\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.dat\");\r\nbyte[] bytes = Files.readAllBytes(file);<\/pre>\n<h4>\uff12-\uff15-\uff12\uff0e\u30d5\u30a1\u30a4\u30eb\u306e\u5185\u5bb9\u3092\u3059\u3079\u3066\u8aad\u307f\u8fbc\u3080<span>(<\/span>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb<span>)<\/span><\/h4>\n<p>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u6642\u306f\u3001<span>java.io.FileReader<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002\u3053\u306e\u4f8b\u306f<span>List<\/span>\u306b\u5168\u3066\u306e\u884c\u3092\u683c\u7d0d\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u306f<span>OutOfMemoryError<\/span>\u304c\u51fa\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nList&lt;String&gt; lines = new ArrayList&lt;&gt;();\r\ntry (BufferedReader br = new BufferedReader(new FileReader(file))) {\r\n\tString line = null;\r\n\twhile ((line = br.readLine()) != null) {\r\n\t\tlines.add(line);\r\n\t}\r\n}<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u6307\u5b9a\u304c\u5fc5\u8981\u306a\u3089\u3001<span>java.io.FileInputStream<\/span>\u3068<span>InputStreamReader<\/span>\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\nList&lt;String&gt; lines = new ArrayList&lt;&gt;();\r\ntry (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), \"MS932\"))) {\r\n\tString line = null;\r\n\twhile ((line = br.readLine()) != null) {\r\n\t\tlines.add(line);\r\n\t}\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nList&lt;String&gt; lines = Files.readAllLines(file); \/\/ \u30d5\u30a1\u30a4\u30eb\u306e\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u304cUTF-8\u306e\u5834\u5408\r\n\/\/ String lines = Files.readString(file); \/\/ Java 11\u4ee5\u964d\u306a\u3089\u4e00\u3064\u306eString\u3068\u3057\u3066\u3082\u8aad\u307f\u8fbc\u3081\u308b<\/pre>\n<h4>\uff12-\uff15-\uff13\uff0e\u30d5\u30a1\u30a4\u30eb\u3078\u66f8\u304d\u8fbc\u3080<span>(<\/span>\u30d0\u30a4\u30ca\u30ea\u30d5\u30a1\u30a4\u30eb<span>)<\/span><\/h4>\n<p>\u30d0\u30a4\u30ca\u30ea\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3080\u969b\u306f\u3001<span>java.io.FileOutputStream<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002\u5927\u304d\u306a\u30c7\u30fc\u30bf\u3092\u51fa\u529b\u3059\u308b\u969b\u306f\u3001<span>java.io.BufferedOutputStream<\/span>\u3092\u4f7f\u3046\u306a\u3069\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">byte[] bytes = { 0x4a, 0x61, 0x76, 0x61 }; \/\/ \"Java\"\r\nFile file = new File(\"\/A\/B\/C.dat\");\r\ntry (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {\r\n\tbos.write(bytes);\r\n}<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nbyte[] bytes = { 0x4a, 0x61, 0x76, 0x61 }; \/\/ \"Java\"\r\nPath file = Paths.get(\"\/A\/B\/C.dat\");\r\nFiles.write(file, bytes);<\/pre>\n<h4>\uff12-\uff15-\uff14\uff0e\u30d5\u30a1\u30a4\u30eb\u3078\u66f8\u304d\u8fbc\u3080<span>(<\/span>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb<span>)<\/span><\/h4>\n<p>\u30c6\u30ad\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u66f8\u304d\u8fbc\u3080\u969b\u306f\u3001<span>java.io.FileWriter<\/span>\u3092\u4f7f\u3044\u307e\u3059\u3002<span>String<\/span>\u3084\u30d7\u30ea\u30df\u30c6\u30a3\u30d6\u578b\u3092\u76f4\u63a5\u6271\u3044\u305f\u3044\u5834\u5408\u306f\u3001<span>java.io.PrintWriter<\/span>\u3092\u4f7f\u3063\u3066\u3082\u826f\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\ntry (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {\r\n\tbw.write(\"Java\");\r\n\tbw.newLine();\r\n}<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u306e\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u6307\u5b9a\u304c\u5fc5\u8981\u306a\u3089\u3001<span>java.io.FileOutputStream<\/span>\u3068<span>OutputStreamWriter<\/span>\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"prettyprint lang:default decode:true\">File file = new File(\"\/A\/B\/C.txt\");\r\ntry (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), \"MS932\"))) {\r\n\tbw.write(\"Java\");\r\n\tbw.newLine();<\/pre>\n<pre class=\"prettyprint lang:default decode:true\">\/\/ NIO.2\u3067\u540c\u3058\u3053\u3068\u3092\u3059\u308b\u5834\u5408\r\nList&lt;String&gt; lines = Arrays.asList(\"Java\");\r\nPath file = Paths.get(\"\/A\/B\/C.txt\");\r\nFiles.write(file, lines);\r\n\/\/ Files.writeString(file, \"Java\"); \/\/ Java 11\u4ee5\u964d\u306e\u5834\u5408<\/pre>\n<h2><span id=\"More_New_IO_APIsNIO2\">\uff13\uff0e\u3010\u53c2\u8003\u3011<span>More New I\/O APIs(NIO.2)<\/span>\u306e\u767b\u5834<\/span><\/h2>\n<p>\u300c<span>JSR 203: More New I\/O APIs for the Java Platform (&#8220;NIO.2&#8221;)<\/span>\u300d\u306f\u3001<span>2011<\/span>\u5e74\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305f<span>Java 7<\/span>\u3067\u5c0e\u5165\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u7279\u5fb4\u306e\u4e00\u3064\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u30fb\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u3059\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9<span>(java.nio.file.Path)<\/span>\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u3092\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9<span>(java.nio.file.Files<\/span>\u7b49<span>)<\/span>\u304c\u5b8c\u5168\u306b\u5206\u96e2\u3055\u308c\u305f\u3053\u3068\u3067\u3059\u3002<span>Files<\/span>\u306e\u30e1\u30bd\u30c3\u30c9\u540d\u3082\u3001\u3088\u308a\u76f4\u611f\u7684\u3067\u7d71\u4e00\u3055\u308c\u305f\u3082\u306e\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>File\u306f<span>Java 1.0<\/span>\u306e\u6642\u4ee3\u304b\u3089\u3042\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<span>Java 1.0<\/span>\u306f\u3001\u4eca<span>(2018<\/span>\u5e74<span>)<\/span>\u304b\u3089<span>20<\/span>\u5e74\u4ee5\u4e0a\u524d\u306b\u8a2d\u8a08\u30fb\u5b9f\u88c5\u3055\u308c\u305f\u3082\u306e\u3067\u3059\u3002\u5f53\u6642\u3068\u306f<span>Java<\/span>\u3092\u52d5\u304b\u3059\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u306e\u6027\u80fd\u30fb\u898f\u6a21\u304c\u5927\u304d\u304f\u5909\u308f\u308a\u3001\u53e4\u3044\u8a2d\u8a08\u3067\u306f\u4eca\u306e\u74b0\u5883\u3067\u6c42\u3081\u3089\u308c\u308b\u6027\u80fd\u3092\u51fa\u3059\u306e\u304c\u96e3\u3057\u304f\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306b\u3001\u5f93\u6765\u306e<span>File<\/span>\u3067\u306f\u69d8\u3005\u306a\u8ab2\u984c\u304c\u3042\u308a\u307e\u3057\u305f\u3002<span>UNIX<\/span>\u3067\u306e\u30b7\u30f3\u30dc\u30ea\u30c3\u30af\u30ea\u30f3\u30af\u3092\u4e0a\u624b\u304f\u6271\u3048\u306a\u304b\u3063\u305f\u308a\u3001\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30c4\u30ea\u30fc\u306e\u63a2\u7d22\u304c\u624b\u8efd\u306b\u51fa\u6765\u306a\u304b\u3063\u305f\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u5c5e\u6027\u306e\u6271\u3044\u3084\u30ea\u30cd\u30fc\u30e0\u3084\u975e\u540c\u671f<span>I\/O<\/span>\u304c\u4e0a\u624b\u304f\u51fa\u6765\u306a\u304b\u3063\u305f\u308a\u3001\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u304c\u6a19\u6e96<span>API<\/span>\u3067\u306f\u7c21\u5358\u306b\u3067\u304d\u306a\u3044<span>(!)<\/span>\u306a\u3069\u3002\u305d\u306e\u89e3\u6c7a\u7b56\u304c<span>NIO.2<\/span>\u3067\u3059\u3002<\/p>\n<p>Java\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u73fe\u5b9f\u306f\u3001<span>NIO.2<\/span>\u306b\u7f6e\u304d\u63db\u308f\u3063\u305f\u3068\u306f\u307e\u3060\u8a00\u3048\u306a\u3044\u72b6\u6cc1\u3067\u3059\u3002\u3067\u3082\u3001<span>NIO.2<\/span>\u306f<span>Java 8<\/span>\u4ee5\u964d\u306e<span>Stream API<\/span>\u306a\u3069\u3068\u306e\u89aa\u548c\u6027\u3082\u9ad8\u304f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3082<span>File<\/span>\u3092\u4f7f\u3046\u3088\u308a\u3082\u305a\u3063\u3068\u7c21\u5358\u306b\u77ed\u304f\u66f8\u3051\u307e\u3059\u3002\u305c\u3072<span>NIO.2<\/span>\u3092\u52c9\u5f37\u3057\u3066\u3001\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2><span id=\"i-6\">\uff14\uff0e\u307e\u3068\u3081<\/span><\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<span>File<\/span>\u306e\u8272\u3005\u306a\u4f7f\u3044\u65b9\u3092\u3056\u3063\u3068\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u3067\u3082<span>File<\/span>\u306e\u5168\u3066\u306e<span>API<\/span>\u3092\u7d39\u4ecb\u3057\u305f\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u306e\u3067\u3001\u8a73\u7d30\u306f<span>JDK<\/span>\u306e<span>Javadoc<\/span>\u7b49\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u4ed6\u306b\u3082\u3044\u308d\u3044\u308d\u4f7f\u3044\u51fa\u304c\u3042\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u306e<span>Java<\/span>\u306e\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306b\u304a\u3051\u308b\u516c\u5f0f\u306a<span>API<\/span>\u306f\u3001<span>Path<\/span>\u3084<span>Files<\/span>\u3092\u4e2d\u5fc3\u3068\u3057\u305f<span>NIO.2<\/span>\u3067\u3059\u3002<span>File<\/span>\u3068\u6bd4\u3079\u3066\u8272\u3005\u3068\u6a5f\u80fd\u304c\u5f37\u5316\u3055\u308c\u3066\u3044\u307e\u3059\u3057\u3001\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9\u3082\u591a\u304f\u3042\u308a\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u81ea\u4f53\u3082\u77ed\u304f\u52b9\u7387\u7684\u306b\u66f8\u3051\u307e\u3059\u3002\u7a4d\u6975\u7684\u306b\u5b66\u3093\u3067\u4f7f\u3044\u3053\u306a\u3059\u3068\u3001\u5468\u56f2\u306e\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u3068\u306e\u5dee\u304c\u30b0\u30c3\u3068\u4ed8\u304d\u307e\u3059\u3088<span>!!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>java.io.File\u306f\u3001Java\u3067\u30d5\u30a1\u30a4\u30eb\u3084\u30c7\u30a3\u30ec\u30af\u30c8\u30ea(=\u30d5\u30a9\u30eb\u30c0)\u306e\u64cd\u4f5c\u3092\u884c\u3048\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\u3001\u524a\u9664\u3001\u5b58\u5728\u78ba\u8a8d\u306a\u3069\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u3067\u5fc5\u8981\u306a\u64cd\u4f5c\u3092\u4e00\u901a\u308a\u884c\u3048\u307e\u3059\u306e\u3067\u3001\u305c\u3072\u4f7f\u3044\u65b9\u3092\u899a\u3048\u305f\u3044\u3082\u306e\u3067\u3059\u306d\u3002 \u306a\u304a [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":804,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1116"}],"collection":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":8,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1116\/revisions"}],"predecessor-version":[{"id":5715,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/posts\/1116\/revisions\/5715"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media\/804"}],"wp:attachment":[{"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bold.ne.jp\/engineer-club\/wp-json\/wp\/v2\/categories?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}