Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Access is Denied with createNewFile() - HELP!

 
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 ]
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic