- public String getFileByteString(File file) throws Exception{
- Base64 b64 = new Base64();
- FileInputStream fis = new FileInputStream(file);
- System.out.print(file.length());
- byte[] buffer = new byte[(int)file.length()];
- System.out.print(buffer.length);
- fis.read(buffer);
- fis.close();
- return b64.encodeToString(buffer);
- }
- /**
- *
- * 把读到的文件串转存
- */
- public void getFileByString(String string, String target) throws Exception{
- Base64 b64 = new Base64();
- byte[] buffer = b64.decode(string);
- FileOutputStream fos = new FileOutputStream(target);
- fos.write(buffer);
- fos.close();
- }
apache commons-codec base64将文件转为字符串
最新推荐文章于 2023-06-28 15:34:03 发布