Copying a file results in java.io.FileNotFoundException (Access is Denied) from output -
file file1 = new file(file.getabsolutefile() + "/example/directory/example.png"); file1.mkdirs(); file1.setwritable(true); file1.createnewfile(); try { fileinputstream = new fileinputstream(exampleinputdirectory); fileoutputstream os = new fileoutputstream(file1); filechannel srcchannel = is.getchannel(); filechannel dstchannel = os.getchannel(); dstchannel.transferfrom(srcchannel, 0, srcchannel.size()); is.close(); os.close(); } catch (ioexception e) { e.printstacktrace(); }
this setup copying image file new directory tree. however, when code executed following:
java.io.filenotfoundexception: *points output directory* (access denied)
have gone creating file1
incorrectly?
the problem here because of using
file1.mkdirs();
and
file1.createnewfile();
together.
since file1
object been given 'directory' attributes after creating directory calling "file1.mkdirs()", again using same object create 'file', means changin attribute of file1 object directory file, not allowed. that's why giving filenotfound
.
Comments
Post a Comment