Я надеюсь, что в моем коде есть очевидная проблема, которую я пропускаю, но я проверяю, существует ли файл, в который я собираюсь записать, и который можно записать. Сбой на fos = new FileOutputStream( file.getPath() );
с FileNotFound
исключением.
File file = new File( cacheDir, url.getFile() );
if ( file.exists() ) {
file.delete();
}
try {
file.mkdirs();
file.createNewFile();
}
catch (IOException e) {
MyLog.e( "Unable to create file: " + file.getPath() );
}
if ( file.exists() && file.canWrite() ) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream( file );
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
if ( !bitmap.compress( CompressFormat.PNG, 100, fos ) ) {
MyLog.e( "Unable to cache image: " + path );
}
if ( fos != null ) {
try {
fos.flush();
fos.close();
}
catch (IOException e) {
e.printStackTrace();
}
}