• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access is Denied with createNewFile() - HELP!  RSS feed

 
Claudia Neri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!