Reputation: 117
I'm doing a download from java apps running on linux. The following is the code:
public void downloadCopyToFile(String filename, String outFilename) throws IOException {
try {
URL url = new URL(filename);
log.info("downloading file from: "+url.toString());
log.info("export to: "+outFilename);
File outFile = new File(outFilename);
FileUtils.copyURLToFile(url, outFile);
} catch (IOException e) {
throw e;
}
}
The parameters for the method is as follows:
filename = https://192.168.100.100:8443/generalLedger20240629140353.xlsx outFilename = c:\temp\generalLedger20240629140353.xlsx
When I run this in windows, it can save to c:\temp, but when I move it to the server running linux, it gives me error 500 java.nio.file.AccessDeniedException: c:\temp\generalLedger20240629140353.xlsx
I'm not sure whther copyURLToFile actually understands that this must be written to windows, because if I change the outFilename to /temp/generalLedger20240629140353.xlsx it actually writes to the linux file system.
I have been working on this for the last 3 days. Please help.
Upvotes: -2
Views: 89
Reputation: 719376
If I am reading your question correctly (it is not very clear!) the problem is arising because you are trying to write to a file called
c:\temp\generalLedger20240629140353.xlsx
on a Linux system.
That didn't work. It would have tried to file whose name started with a c:
in the current directory. The exception says that your application didn't have permission to do that. Probably the current directory's ownership, access mode and/or ACL doesn't allow it.
But even if it allowed it, that would have been the wrong thing to do.
Drive letters (like "c:") are only a thing on Windows. On Linux, Unix, MacOS and so forth, "c:" would be interpreted as part of a simple file name.
I'm not sure whether copyURLToFile actually understands that this must be written to windows, because if I change the outFilename to "/temp/generalLedger20240629140353.xlsx" it actually writes to the linux file system.
(Yes, that's the correct way to do it. Assuming you want to write to the Linux file systems.)
Java's copyURLToFile
doesn't understand that you want to write that to windows. And even if it understood what you wanted, Java on Linux doesn't know how to write files to Windows. When are running a program on a Linux system, the file system is the local >>Linux<< file system on >>this<< machine, not a file system on some other machine.
But maybe that's not what you mean ...
One possibility is that you have a dual boot machine (Linux and Windows) and you have booted Linux and want to write to the machine's Windows file system. That is possible ... but the Linux OS will need to mount the Windows NTFS (or FAT) file system. You will need to use Linux pathname syntax: no drive letters!
Another possibility is that the Windows file system you are trying to write to is a Windows (SMB) file share. Once again, to do that Linux needs to mount the file share, and you then use Linux pathname syntax to access the files.
Upvotes: 0