Base64 转 File public File base64ToFile(String base64, String filePath) { File file = new File(filePath); b
Base64 转 File
public File base64ToFile(String base64, String filePath) { File file = new File(filePath); byte[] buffer; try { BASE64Decoder base64Decoder = new BASE64Decoder(); buffer = base64Decoder.decodeBuffer(base64); FileOutputStream out = new FileOutputStream(filePath); out.write(buffer); out.close(); } catch (Exception e) { Log.e("TAG", "异常信息:" + e.getMessage()); } return file; }
File 转 Base64
public String fileToBase64(String filePath) {File file = new File(filePath);FileInputStream inputFile;try {inputFile = new FileInputStream(file);byte[] buffer = new byte[inputFile.available()];inputFile.read(buffer);inputFile.close();BASE64Encoder base64Encoder = new BASE64Encoder();Log.i("encodeFileToBase64", "encode = " + base64Encoder.encode(buffer));return base64Encoder.encode(buffer);} catch (Exception e) {Log.e("TAG", "异常信息:" + e.getMessage());}return "";}
来源地址:https://blog.csdn.net/victor_E_N_01185/article/details/130274460
--结束END--
本文标题: Java Base64 和 File 之间互转
本文链接: https://www.lsjlt.com/news/423433.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0