Edo*_*edo 8 java base64 android fileoutputstream android-studio
我想解码一个base64字符串并将其转换为一个文件(如pdf/jpg)并将其保存到设备,例如在(/storage/emulated/0/Download/file.pdf)中.
对于编码文件我使用此代码:
File originalFile = new File("/mnt/sdcard/download/file.pdf");
String encodedBase64 = null;
try {
FileInputStream fileInputStreamReader = new FileInputStream(originalFile);
byte[] bytes = new byte[(int) originalFile.length()];
fileInputStreamReader.read(bytes);
encodedBase64=Base64.encodeToString(bytes,Base64.NO_WRAP);
messaggio=encodedBase64.toString();
//encodedBase64 = new String(Base64.encode(bytes));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
现在,我想取消这个base64字符串并将其转换为文件并将其保存在设备上...
有人能帮我吗?
谢谢大家=)
Pre*_*ola 17
你可以试试这个:
FileOutputStream fos = new FileOutputStream(filepath);
fos.write(Base64.decode(base64String, Base64.NO_WRAP));
fos.close();
Run Code Online (Sandbox Code Playgroud)
哪里:
filepath: 新文件的路径base64String: 您要转换的base64字符串| 归档时间: |
|
| 查看次数: |
39002 次 |
| 最近记录: |