{"id":153,"date":"2018-01-21T20:16:44","date_gmt":"2018-01-21T14:16:44","guid":{"rendered":"https:\/\/qtvz.com\/?p=153"},"modified":"2018-01-21T20:19:41","modified_gmt":"2018-01-21T14:19:41","slug":"android%e6%96%87%e4%bb%b6%e5%92%8cbase64%e4%ba%92%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/qtvz.com\/153.html","title":{"rendered":"Android\u6587\u4ef6\u548cbase64\u4e92\u8f6c"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u5728\u9879\u76ee\u4e2d\u9700\u8981\u7528\u5230\u6587\u4ef6\u4f20\u8f93\u5165\uff0c\u6709\u65f6\u9700\u8981\u5c06\u6587\u4ef6\u8f6c\u6210base64\u5b57\u4e32\uff0c\u518d\u5c06base64\u5b57\u4e32\u8f6c\u6210\u5b57\u8282\u6d41\u4fdd\u5b58\u5728\u6587\u4ef6\u4e86\u3002<\/p>\n<pre class=\"lang:default decode:true \">\/**\r\n* \u5c06\u6587\u4ef6\u8f6c\u6210base64 \u5b57\u7b26\u4e32\r\n* @param path \u6587\u4ef6\u8def\u5f84\r\n* @return\r\n* @throws Exception\r\n*\/\r\npublic static String encode<a href=\"https:\/\/qtvz.com\/tag\/base64\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e Base64 \u7684\u6587\u7ae0\" target=\"_blank\">Base64<\/a>File(String path) throws Exception {\r\n    File  file = new File(path);\r\n    FileInputStream inputFile = new FileInputStream(file);\r\n    byte[] buffer = new byte[(int)file.length()];\r\n    inputFile.read(buffer);\r\n    inputFile.close();\r\n    return new BASE64Encoder().encode(buffer);\r\n}\r\n\/**\r\n* \u5c06base64\u5b57\u7b26\u89e3\u7801\u4fdd\u5b58\u6587\u4ef6\r\n* @param base64Code\r\n* @param targetPath\r\n* @throws Exception\r\n*\/\r\npublic static void decoder<a href=\"https:\/\/qtvz.com\/tag\/base64\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e Base64 \u7684\u6587\u7ae0\" target=\"_blank\">Base64<\/a>File(String base64Code,String targetPath) throws Exception {\r\n    byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);\r\n    FileOutputStream out = new FileOutputStream(targetPath);\r\n    out.write(buffer);\r\n    out.close();\r\n}\r\n\/**\r\n* \u5c06base64\u5b57\u7b26\u4fdd\u5b58\u6587\u672c\u6587\u4ef6\r\n* @param base64Code\r\n* @param targetPath\r\n* @throws Exception\r\n*\/\r\npublic static void toFile(String base64Code,String targetPath) throws Exception {\r\n    byte[] buffer = base64Code.getBytes();\r\n    FileOutputStream out = new FileOutputStream(targetPath);\r\n    out.write(buffer);\r\n    out.close();\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u5728\u9879\u76ee\u4e2d\u9700\u8981\u7528\u5230\u6587\u4ef6\u4f20\u8f93\u5165\uff0c\u6709\u65f6\u9700\u8981\u5c06\u6587\u4ef6\u8f6c\u6210base64\u5b57\u4e32\uff0c\u518d\u5c06base64\u5b57\u4e32\u8f6c\u6210\u5b57\u8282\u6d41\u4fdd\u5b58\u5728\u6587\u4ef6\u4e86\u3002 \/** * \u5c06\u6587\u4ef6\u8f6c\u6210base64 \u5b57\u7b26\u4e32 * @param path \u6587\u4ef6\u8def\u5f84 * @r \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,4],"tags":[51],"views":37338,"_links":{"self":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/153"}],"collection":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/comments?post=153"}],"version-history":[{"count":2,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":155,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/posts\/153\/revisions\/155"}],"wp:attachment":[{"href":"https:\/\/qtvz.com\/api\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qtvz.com\/api\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}