{"id":2398,"date":"2018-05-05T15:45:10","date_gmt":"2018-05-05T06:45:10","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=2398"},"modified":"2023-05-27T20:36:44","modified_gmt":"2023-05-27T11:36:44","slug":"%e3%80%90java%e3%80%91%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e6%9b%b8%e3%81%8d%e8%be%bc%e3%81%bf","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=2398","title":{"rendered":"\u3010Java\u3011\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\uff08\u30b5\u30f3\u30d7\u30eb\u3042\u308a\uff09"},"content":{"rendered":"<h2>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f<\/h2>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:default decode:true\">public class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t    try {\r\n\r\n\t    \tFileReader fr = new FileReader(\"C:\/develop\/test.txt\");\r\n\r\n            int data;\r\n\r\n            while ((data = fr.read()) != -1) {\r\n                System.out.print((char) data);\r\n            }\r\n\r\n            fr.close();\r\n\r\n\t     } catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\r\n\t}\r\n}<\/pre>\n<h3>\u89e3\u8aac<\/h3>\n<h4>data = fr.read()) != -1<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>FileReader\u306b\u306f\u3001String\u3092\u8fd4\u3059\u3088\u3046\u306a\u6587\u5b57\u5217\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><span style=\"color: #000000;\">\u306a\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u975e\u5e38\u306b\u3081\u3093\u3069\u3046\u3067\u3059\u304c\u3001<\/strong><\/span>read\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u6587\u5b57\u3092\u4e00\u6587\u5b57\u305a\u3064\u53d6\u308a\u51fa\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/span><\/p>\n<p>\u305f\u3060\u3001<span style=\"color: #ff0000;\"><strong>read\u306e\u623b\u308a\u5024\u3068\u3057\u3066int\u578b\u304c\u8fd4\u3063\u3066\u6765\u308b\u306e\u3067\u3001\u51e6\u7406\u3059\u308b\u969b\u306f\u3001char\u578b\u306b\u30ad\u30e3\u30b9\u30c8\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\u3053\u308c\u306f\u3001\u7d42\u7aef\u307e\u3067\u8a00\u3063\u305f\u969b\u306e\u5370\u3068\u3057\u3066\u3001\u300c-1\u300d\u3092\u8fd4\u3059\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001char\u578b\u3067\u306f\u305d\u3046\u3057\u305f\u7d42\u7aef\u306e\u6570\u5b57\u3092\u6271\u3048\u306a\u3044\u306e\u3067\u3001\u82e6\u8089\u306e\u7b56\u3068\u3057\u3066int\u578b\u304c\u8fd4\u308b\u4ed5\u69d8\u3068\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u3088\u3046\u3067\u3059\u3002<\/p>\n<h2>\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f<\/h2>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<pre class=\"lang:default decode:true\">import java.io.FileWriter;\r\nimport java.io.IOException;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t    try {\r\n\t    \tFileWriter fw = new FileWriter(\"c:\/develop\/test.txt\",false);\r\n\t    \tfw.write(\"Hello World\");\r\n\t    \tfw.flush();\r\n\t    \tfw.close();\r\n\t\t} catch (IOException e) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\r\n\t}\r\n}<\/pre>\n<h3>\u89e3\u8aac<\/h3>\n<h4>FileWriter fw = new FileWriter(\"c:\/develop\/test.txt\",false);<\/h4>\n<p>FileWriter\u30af\u30e9\u30b9\u3092\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3057\u3001\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u4e0a\u66f8\u304d\u3057\u3001\u306a\u3044\u5834\u5408\u306f\u65b0\u898f\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u7b2c\u4e8c\u5f15\u6570\u306efalse\u306f\u3001\u66f8\u304d\u8fbc\u3080\u969b\u306f\u3001\u5fc5\u305a\u5148\u982d\u304b\u3089\u6587\u5b57\u3092\u66f8\u304d\u8fbc\u3093\u3067\u3044\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>fw.write(\"Hello World\");<\/h4>\n<p>\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u3001\u300cHello World\u300d\u3068\u3044\u3046\u6587\u5b57\u5217\u306e\u66f8\u304d\u8fbc\u307f\u3092\u8981\u6c42\u3057\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u3059\u3050\u306b\u66f8\u304d\u8fbc\u307e\u308c\u308b\u308f\u3051\u3067\u306a\u304f\u3001\u4e00\u65e6\u300c\u30d0\u30c3\u30d5\u30a1\u300d\u306b\u305f\u3081\u3066\u304a\u304d\u3001\u5f8c\u3067\u307e\u3068\u3081\u3066\u66f8\u304d\u8fbc\u3080\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u306a\u306e\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u5fc5\u305a\u3057\u3082\u30d5\u30a1\u30a4\u30eb\u306b\u6b63\u3057\u304f\u66f8\u304d\u8fbc\u307e\u308c\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u3068\u3044\u3046\u70b9\u306f\u6ce8\u610f<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<h4>fw.flush();<\/h4>\n<p>\u9589\u3058\u308b\u524d\u306b\u306f\u3001\u5fc5\u305a\u66f8\u304d\u307e\u3057\u3087\u3046\u3002<span style=\"color: #ff0000;\"><strong>\u3053\u308c\u3092\u66f8\u304b\u306a\u3044\u3068\u3001write\u30e1\u30bd\u30c3\u30c9\u3060\u3051\u3067\u306f\u3001\u6b63\u3057\u304f\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307e\u308c\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<p>JVM\u306b\u5bfe\u3057\u3066\u3001\u3082\u3057\u6b20\u640d\u3057\u3066\u3044\u308b\u6587\u5b57\u30c7\u30fc\u30bf\u304c\u3042\u308c\u3070\u3001\u5f37\u5236\u7684\u306b\u66f8\u304d\u8fbc\u3093\u3067\u304f\u308c\u3068\u3044\u3046\u8981\u6c42\u3092\u3059\u308b\u306e\u3067\u3001\u66f8\u304d\u6f0f\u3089\u3057\u3092\u9632\u3052\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f \u30b5\u30f3\u30d7\u30eb public class Main { public static void main(String[] args) { try { FileReader fr = new File [&hellip;]","protected":false},"author":1,"featured_media":2405,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2398"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2398"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2398\/revisions"}],"predecessor-version":[{"id":20233,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/2398\/revisions\/20233"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/2405"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2398"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}