Tôi đang cố gắng chuyển đổi tệp từ sdcard sang Base64 nhưng có vẻ như tệp quá lớn và tôi nhận được lỗi OutOfMemoryError.Chuyển đổi tệp (<100Mo) trong Base64 trên Android
Đây là mã của tôi:
InputStream inputStream = null;//You can get an inputStream using any IO API
inputStream = new FileInputStream(file.getAbsolutePath());
byte[] bytes;
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
bytes = output.toByteArray();
attachedFile = Base64.encodeToString(bytes, Base64.DEFAULT);
Có cách nào để đi xung quanh OutOfMemoryError khi nộp String attachedFile?
Sử dụng mã này nó sẽ rất hữu ích https://stackoverflow.com/a/47572643/3505534 – R2R