Java – ignore ‘file Result of mkdirs() ‘
•
Java
This is mydir My code in mkdirs(); This code shows that I ignored file Result warning for mkdirs()
I tried to fix this warning, but I failed
private void saveGIF() {
Toast.makeText(getApplicationContext(),"Gif Save",Toast.LENGTH_LONG).show();
String filepath123 = BuildConfig.VERSION_NAME;
try {
File myDir = new File(String.valueOf(Environment.getExternalStorageDirectory().toString()) + "/" + "NewyearGIF");enter code here
//My Statement Code This Line Show Me that Warning
myDir.mkdirs();
File file = new File(myDir,"NewyearGif_" + System.currentTimeMillis() + ".gif");
filepath123 = file.getPath();
InputStream is = getResources().openRawResource(this.ivDrawable);
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] img = new byte[AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT];
while (true) {
int current = bis.read();
if (current == -1) {
break;
}
baos.write(current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(baos.toByteArray());
fos.flush();
fos.close();
is.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent mediaScanIntent = new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE");
mediaScanIntent.setData(Uri.fromFile(new File(filepath123)));
sendBroadcast(mediaScanIntent);
}
Solution
The method mkdirs has a Boolean return value that you did not use
boolean wasSuccessful = myDir.mkdirs();
The create operation returns a value indicating whether the directory was created successfully For example, the result value wassuccessful can be used to display errors when errors occur
if (!wasSuccessful) {
System.out.println("was not successful.");
}
Boolean return values from around Java docs:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
