'Flutter OS Error: File exists, errno = 17

MY ERROR -

Unhandled Exception: FileSystemException: Cannot open file, path = '/storage/emulated/0/Download/Music/a.png' (OS Error: File exists, errno = 17)

First I create an image file and if I delete this file from the file manager application I get an error like this.

I also get this error if I want to delete the file programmatically.

FileSystemException: Cannot delete file, path = '/storage/emulated/0/Download/Music/a.png' (OS Error: No such file or directory, errno = 2)

MY CODE EXAMPLE

Future<String> getImg(imgUrl, path2, name) async {

  File fileimg = new File(join(path2, name + '.png'));
  if (fileimg.existsSync()) fileimg.deleteSync();
  var response = await http.get(Uri.parse(imgUrl));
  fileimg.writeAsBytesSync(response.bodyBytes);
  return fileimg.path;
}

Actually there is no file but there is



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source