Ответ 1
@SuppressWarnings ( "TryFinallyCanBeTryWithResources" ) сделал трюк:)
У меня есть этот фрагмент кода
private void copyFile(File src, File dst) throws IOException {
FileChannel inChannel = new FileInputStream(src).getChannel();
FileChannel outChannel = new FileOutputStream(dst).getChannel();
try {
inChannel.transferTo(0, inChannel.size(), outChannel);
}finally {
if(inChannel != null) {
inChannel.close();
}
outChannel.close();
}
}
который генерирует раздражающее предупреждение "попробуйте использовать автоматическое управление ресурсами". Пролет: я не могу использовать Java 7 try-with-resources, потому что мое приложение нацелено на уровень api 14 (получило ошибку, если я его использую). Есть ли способ подавить это раздражающее предупреждение?
@SuppressWarnings ( "TryFinallyCanBeTryWithResources" ) сделал трюк:)
@SuppressLint("NewApi")
также будет работать =)
И например:
@SuppressLint("NewApi")
public static File saveImage(Bitmap bitmap) {
File file = null;
if (isExternalStorageWritable()) {
file = new File(getFolderStorageDirectory(), getFileNameImage());
try (FileOutputStream out = new FileOutputStream(file)) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (Exception e) {
e.getMessage();
}
}
return file;
}
Надеюсь, что это поможет!