• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Copying files.

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code looks correct.

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.
 
Sheriff
Posts: 22258
119
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote:Your code looks correct.


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.
 
Chris Swanson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic