The problem here is because of using
file1.mkdirs();
and
file1.createNewFile();
together.
Since the file1
object is already been given 'directory' attributes after creating it as directory by calling "file1.mkdirs()", but then you are again using the same object to create a 'file', that means changin attribute of file1 object from directory to a file, which is not allowed. that's why its giving you FileNotFound
.