【发布时间】:2013-11-18 14:35:16
【问题描述】:
我有 .zip 文件,在上传到服务器之前我必须对其进行 Base64 编码。给定文件最大为 20 mb,这会导致 OutOfMemory 异常。 我使用此代码:
public String encodeZipToBase64(File zip) {
StringBuffer sb = new StringBuffer();
byte fileContent[] = new byte[1024];
try
{
FileInputStream fin = new FileInputStream(zip);
while(fin.read(fileContent) >= 0) {
sb.append(Base64.encodeToString(fileContent, Base64.DEFAULT)); //exception here
}
} catch(OutOfMemoryError e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
附加到 StringBuilder 时发生异常。我可以做些什么来解决它?
谢谢!
【问题讨论】:
标签: android zip base64 out-of-memory