I am trying to copy over some files from one file to another, but I keep getting access denied errors as an exception. Right now I am using this segment of code. How can I get around this? I have a database which stores the location of these files, and I need to do a hard copy of many files to another.
Error messages such as "access denied" indicate that the operating system for some reason doesn't allow your program to write a file in a specific location. Check if you have the rights to write to the directory where you are trying to copy the file, if there's enough free disk space, if there isn't already an existing file with the same name as your output file that's opened by another process (so that you can't overwrite it at that moment), etc.
I would make one change though - put the closing in finally blocks. By using nested try blocks you can skip any null checks, and it will also make it safer in case in.close() would throw an exception. The code:
The inner-most try-finally statement will make sure that whatever happens, out is closed. The try-finally around that will make sure that whatever happens, in is closed.
This issue has come up again, and is the main barrier preventing me from completing my program.
How do people normally store images when they need to be copied? Should I store the location of the file within the database and find ways around the operating system. If so, can I get any suggestions on how to accomplish this?
Otherwise, should I store the image in the database itself? I know this is difficult, and from what I have read not recommended.