Link to home
Start Free TrialLog in
Avatar of e-genpartners
e-genpartners

asked on

Files.copy java.nio.file.AccessDeniedException

I want to copy into my local folder the directories and files in each directory through http.

I have run the following Java codes and the error message as below comes up.

How can i address this problem?

boolean getLogfilesFromURL(String inFileFolder, String URLRemote  ) throws MalformedURLException, IOException{
             Path path = Paths.get(inFileFolder );
                       URI u = URI.create(URLRemote);//"http://java.sun.com/");
                       try (InputStream in = u.toURL().openStream()) {
                         Files.copy(in, path);
                       }
                        
            return true;            
      }
java.nio.file.AccessDeniedException: data
      at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
      at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
      at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
      at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
      at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source)
      at java.nio.file.Files.newOutputStream(Unknown Source)
      at java.nio.file.Files.copy(Unknown Source)
      at data_management.ImportDataFromURLToEnTrak.getLogfilesFromURL(ImportDataFromURLToEnTrak.java:65)
      at data_management.ImportDataFromURLToEnTrak.main(ImportDataFromURLToEnTrak.java:668)
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of e-genpartners
e-genpartners

ASKER

Is there any way to copy all files and directories over the HTTP(or FTP) into my local folder?
I am looking for an auotomatic process to copy whole files from the remote source to my local folder as they are.

Thanks.
There's no reliable way with http unless the web server has listing turned on (and then you've still work to do)

If ftp is supported on the server, that's another issue. You'd then use an ftp api for Java
It is very helpful.
Do you have recommendable sample codes with the FTP API ?
with the FTP API ?
Which ftp api? It will generally be with whatever you use
:)

Apache Commons Net is often used for ftp

http://commons.apache.org/proper/commons-net/