Cannot copy file to windows 11 file system – if you are running this code in the linux server

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:tempgeneralLedger20240629140353.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:tempgeneralLedger20240629140353.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. Thanks.

8

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:tempgeneralLedger20240629140353.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.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật