{"id":936,"date":"2018-09-17T18:37:49","date_gmt":"2018-09-17T09:37:49","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=936"},"modified":"2019-10-04T02:02:07","modified_gmt":"2019-10-03T17:02:07","slug":"dateikopie","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/de\/blog\/java\/file-copy","title":{"rendered":"Java-Datei kopieren (Puffergr\u00f6\u00dfe \u00e4ndern)"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Java \u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\uff08\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5909\u66f4\uff09<\/a><\/h2>\n<p>\n\u3000Java \u3067 <strong>java.io.InputStream<\/strong>\u3001<strong>java.io.OutputStream<\/strong> \u3067\u306e<br \/>\n\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u5229\u7528\u3057\u305f\u30b3\u30d4\u30fc\u51e6\u7406\u3092\u884c\u3046\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u5229\u7528\u3057\u305f\u30b3\u30d4\u30fc\u51e6\u7406\u3067\u306f\u3001\u8aad\u307f\u8fbc\u307f\u30d0\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5927\u304d\u304f\u3059\u308b\u3053\u3068\u3067\u3001\u5927\u304d\u306a\u30d5\u30a1\u30a4\u30eb\u3067\u3082\u6bd4\u8f03\u7684\u9ad8\u901f\u306b\u30b3\u30d4\u30fc\u3092\u884c\u3048\u307e\u3059\u3002<br \/>\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30fc\u30b5\u30a4\u30ba\u3092\u5f15\u6570\u3067\u6307\u5b9a\u53ef\u80fd\u3068\u3057\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<p>\n\u3000\u6307\u5b9a\u3057\u305f\u8aad\u307f\u8fbc\u307f\u30d0\u30d5\u30a1\u9818\u57df\u306fJavaVM\u306e\u30d2\u30fc\u30d7\u5185\u306b\u78ba\u4fdd\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u3042\u307e\u308a\u5927\u304d\u304f\u3057\u3059\u304e\u3066\u3082\u52b9\u7387\u304c\u60aa\u304f\u306a\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b\u4e0a\u3067\u3001\u52b9\u7387\u306e\u826f\u3044\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u306b\u3064\u3044\u3066\u3082\u540c\u6642\u306b\u78ba\u8a8d\u3057\u307e\u3059\u3002\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/a><\/h2>\n<p><textarea readonly=\"readonly\" style=\"font-size: 13px;height: 400px;\" class=\"src\" onclick=\"this.focus();this.select()\">\/**<br \/>\n * \u30b3\u30d4\u30fc\u5143\u306e\u30d1\u30b9[srcPath]\u304b\u3089\u30b3\u30d4\u30fc\u5148\u306e\u30d1\u30b9[destPath]\u3078\u30d5\u30a1\u30a4\u30eb\u306e\u30b3\u30d4\u30fc<br \/>\n * \u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n * @param srcPath    \u30b3\u30d4\u30fc\u5143\u306e\u30d1\u30b9<br \/>\n * @param destPath    \u30b3\u30d4\u30fc\u5148\u306e\u30d1\u30b9<br \/>\n * @param bufferSize    \u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba(KB)\u3067\u3059\u3002<br \/>\n * @throws IOException    \u4f55\u3089\u304b\u306e\u5165\u51fa\u529b\u51e6\u7406\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408<br \/>\n *\/<br \/>\npublic static void copyStream(String srcPath, String destPath,<br \/>\n    int bufferSize) throws IOException {<br \/>\n    InputStream in = new FileInputStream(srcPath);<br \/>\n    OutputStream os = new FileOutputStream(destPath);<br \/>\n    copyStream(in, os, bufferSize);<br \/>\n}<\/p>\n<p>\/**<br \/>\n * \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u304b\u3089\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3078\u30c7\u30fc\u30bf\u306e\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3044\u307e\u3059\u3002<br \/>\n * \u5c1a\u3001\u30b3\u30d4\u30fc\u51e6\u7406\u7d42\u4e86\u5f8c\u3001\u5165\u529b\u30fb\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u9589\u3058\u307e\u3059\u3002<br \/>\n * @param in    \u5165\u529b\u30b9\u30c8\u30ea\u30fc\u30e0<br \/>\n * @param os    \u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0<br \/>\n * @param bufferSize \u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba(KB)\u3067\u3059\u3002<br \/>\n * @throws IOException    \u4f55\u3089\u304b\u306e\u5165\u51fa\u529b\u51e6\u7406\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u5834\u5408<br \/>\n *\/<br \/>\npublic static void copyStream(InputStream in, OutputStream os,<br \/>\n    int bufferSize) throws IOException {<br \/>\n    int len = -1;<br \/>\n    byte[] b = new byte[bufferSize * 1024];<br \/>\n    try {<br \/>\n        while ((len = in.read(b, 0, b.length)) != -1) {<br \/>\n            os.write(b, 0, len);<br \/>\n        }<br \/>\n        os.flush();<br \/>\n    } finally {<br \/>\n        if (in != null) {<br \/>\n            try {<br \/>\n                in.close();<br \/>\n            } catch (IOException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        }<br \/>\n        if (os != null) {<br \/>\n            try {<br \/>\n                os.close();<br \/>\n            } catch (IOException e) {<br \/>\n                e.printStackTrace();<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\n<\/textarea><\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"3\">\u5b9f\u884c<\/a><\/h2>\n<p>\n\u3000\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u3092\u884c\u3046\u305f\u3081\u306b\u3001C\u30c9\u30e9\u30a4\u30d6\u76f4\u4e0b\u306b 100MB \u306e\u30d5\u30a1\u30a4\u30eb\u300c100M.txt\u300d\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u3001 <i>C:\\100M.txt<\/i> \u3092\u3001\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u30001000KB\u3000\u5358\u4f4d\u3067\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f <i>C:\\a.txt<\/i>  \u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002<\/p>\n<p>\u5c1a\u3001\u30b5\u30f3\u30d7\u30eb\u306e\u5b9f\u884c\u306f\u4ee5\u4e0b\u306e\u74b0\u5883\u3067\u884c\u3044\u307e\u3057\u305f\u3002<br \/>\nOS : WindowsXP<br \/>\nCPU : Athlon 1.46GHz<br \/>\n\u30e1\u30e2\u30ea\u30fc : 1GB<br \/>\nJRE : 1.6.4\n<\/p>\n<p>\u25c6\u5b9f\u884c\u4f8b<\/p>\n<pre class=\"sample_src\">\/**\r\n * \u5b9f\u884c\u4f8b\r\n * @param args\r\n *\/\r\npublic static void main(String[] args) {\r\n    try {\r\n        copyStream(\"C:\\\\100M.txt\", \"C:\\\\a.txt\",1000);\r\n    } catch (IOException e) {\r\n        e.printStackTrace();\r\n    }\r\n}\r\n<\/pre>\n<p>\u25c6\u5b9f\u884c\u7d50\u679c<br \/>\n<a href=\"https:\/\/chat-messenger.com\/images\/file_copy.jpg\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/file_copy.jpg\" alt=\"\" border=\"0\"><\/a><br clear=\"all\"><\/p>\n<h2 class=\"common_title\"><a name=\"4\">\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u306e\u5909\u66f4<\/a><\/h2>\n<p>\n\u3000\u30d5\u30a1\u30a4\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b\u4e0a\u3067\u3001\u52b9\u7387\u306e\u826f\u3044\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u3001copyStream \u306e\u7b2c3\u5f15\u6570\u306b<br \/>\n1KB\u3001100KB\u30011000KB\u300110000KB\u5358\u4f4d\u3067\u540c\u69d8\u306e\u30b3\u30d4\u30fc\u51e6\u7406\u3092\u884c\u3063\u305f\u7d50\u679c\u3092\u4ee5\u4e0b\u306b\u307e\u3068\u3081\u3066\u3044\u307e\u3059\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/chat-messenger.com\/images\/file_copy_stream_reslt.jpg\" alt=\"\" border=\"0\"><br clear=\"all\"><br \/>\n<br \/>\n\u3000\u4e0a\u8a18\u306e\u7d50\u679c\u3060\u3051\u3067\u65ad\u5b9a\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u304c\u3001\u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092 1000KB \u5358\u4f4d\u306b\u6307\u5b9a\u3059\u308b\u3068\u3001<br \/>\n\u30b3\u30d4\u30fc\u51e6\u7406\u4e2d\u306e\u30d2\u30fc\u30d7\u4f7f\u7528\u91cf\u3001\u51e6\u7406\u6642\u9593\u306b\u304a\u3044\u3066\u52b9\u7387\u304c\u826f\u3044\u3068\u8a00\u3046\u7d50\u679c\u304c\u51fa\u307e\u3057\u305f\u3002<br \/>\n\u5c1a\u3001\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u5927\u304d\u304f\u3057\u305f\u5834\u5408\uff08 1GB \u7a0b\u5ea6\uff09\u3067\u3082\u540c\u69d8\u306e\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u9006\u306b\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u3044\u30d5\u30a1\u30a4\u30eb\uff08 1MB \u4ee5\u4e0b\u3050\u3089\u3044 )\u3092\u30b3\u30d4\u30fc\u3059\u308b\u5834\u5408\u306f\u3001\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5927\u304d\u304f\u3057\u3066\u3082\u7121\u99c4\u306b\u306a\u308a\u307e\u3059\u306e\u3067 100KB \u3050\u3089\u3044\u3067\u6307\u5b9a\u3059\u308b\u306e\u304c\u826f\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002\n<\/p>\n\n<h2 class=\"common_title\"><a name=\"5\">FileChannel\u3092\u5229\u7528\u3057\u3066\u3082\u3063\u3068\u9ad8\u901f\u306b<\/a><\/h2>\n<p><a name=\"5\"><\/a><\/p>\n<p><a name=\"5\"><br \/>\n\u3000<strong>java.io.InputStream<\/strong>\u3001<strong>java.io.OutputStream<\/strong><br \/>\n\u3067\u306e\u30b3\u30d4\u30fc\u51e6\u7406\u306f\u5165\u51fa\u529b\u30b9\u30c8\u30ea\u30fc\u30e0\u3092\u7406\u89e3\u3059\u308b\u4e0a\u3067\u3001\u91cd\u8981\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001<br \/>\nJ2SE1.4 \u3067\u5c0e\u5165\u3055\u308c\u305f New I\/O \u306e <strong>java.nio.channels.FileChannel#transferTo<\/strong><br \/>\n\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u3055\u3089\u306b\u52b9\u7387\u826f\u304f\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n\u6b21\u306f\u3001FileChannel \u3092\u5229\u7528\u3057\u3066\u7c21\u5358\u30fb\u9ad8\u901f\u306b\u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\u3092\u884c\u3046\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<br \/>\n\u21d2 <\/a><a href=\"https:\/\/chat-messenger.com\/blog\/java\/filechannel-transferto\"><strong>Java \u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\uff08\u7c21\u5358\u30fb\u9ad8\u901f\uff09<\/strong><\/a><br \/>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java \u30d5\u30a1\u30a4\u30eb\u30b3\u30d4\u30fc\uff08\u30d0\u30c3\u30d5\u30a1\u30b5\u30a4\u30ba\u3092\u5909\u66f4\uff09 \u3000Java \u3067 java.io.InputStream\u3001ja [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-936","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/posts\/936","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/comments?post=936"}],"version-history":[{"count":6,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/posts\/936\/revisions"}],"predecessor-version":[{"id":4541,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/posts\/936\/revisions\/4541"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/media?parent=936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/categories?post=936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/de\/wp-json\/wp\/v2\/tags?post=936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}