下载文件并删除文件时,我正在捕获IOException。不幸的是,SD卡上的空间没有立即释放,但此刻,应用程序关闭。有可能直接这样做吗?该应用程序稍后需要一些可用空间,否则会崩溃......
public boolean writeToFile(InputStream source, String destination) {
File file = new File(destination);
try {
file.createNewFile();
OutputStream output = new BufferedOutputStream(new FileOutputStream(file));
byte[] buf = new byte[Utils.CHUNK_SIZE];
int len;
while ((len = source.read(buf)) > 0) {
output.write(buf, 0, len);
bytesReceived += len;
publishProgress();
}
output.close();
return true;
} catch (IOException e) {
// no write access or sd card full
file.delete();
return false;
}
}