• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Access is Denied with createNewFile() - HELP!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a backup class, the full() method should delete what's in the destination and recreate everything.
When the destination directory is empty and I run it, it works fine.
If the destination isn't empty, it deletes the contents, creates the root directory which will then contain all the subdirectories.
It works properly if the destination folder is not modified, if a folder is added to it, but if a file is added and you then run full(), (which should delete everything, including the newly created file, and they copy the contents of the source), it gives the following message whenever it tries to create a file(but not a directory): java.io.IOException: Access is denied
I think it might have something to do with the createNewFile() method.
Please find below the code for the Backup.java class

*Code tags added for easier reading -- Jason*
[ March 18, 2004: Message edited by: jason adam ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, my guess would be that there's a bug in copyFile(), but you haven't shown us the code for that. Be sure it closes the files it opens.
 
Claudia Neri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a million for your reply.
Here's the code for the copyFile()...as far as I can see it is closing all the files.
What do you think?
/**
* method to copy files.
* @return void
* @param String inName
* @param String outName
* @throw IOException
*/
public static void copyFile(String inName, String outName)throws IOException
{
BufferedInputStream is = new BufferedInputStream(
new FileInputStream(inName));
BufferedOutputStream os = new BufferedOutputStream(
new FileOutputStream(outName));
copyDataFile( is, os, true);
}// end of copyFile
//----------------------------------------------------------------
/**
* method to copy files.
* @return void
* @param InputStream is
* @param OutputStream os
* @param boolean close
* @throw IOException
*/
public static void copyDataFile(InputStream is, OutputStream os, boolean close) throws IOException
{
int b;
while(( b = is.read()) != -1 )
{
os.write( b );
}
is.close();
if( close )
os.close();
}//end of copyDataFile
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic