久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Java 使用 JakartaFtpWrapper 上傳 jpg - 使文件不可讀

Java upload jpg using JakartaFtpWrapper - makes the file unreadable(Java 使用 JakartaFtpWrapper 上傳 jpg - 使文件不可讀)
本文介紹了Java 使用 JakartaFtpWrapper 上傳 jpg - 使文件不可讀的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我一直在使用 JakartaFtpWrapper 將文件從客戶端 Java 應(yīng)用程序上傳到我的服務(wù)器(用于備份目的).

I've been using JakartaFtpWrapper to upload files from the client Java application to my server (for backup purposes).

上傳的文件有文本文件、png文件和jpgs.

The files that are uploaded are text files, png files and jpgs.

我注意到在本地機器上有效的 jpg 文件在服務(wù)器(它們被 FTP 傳輸?shù)降奈恢?上不知何故變得不可讀(損壞的文件).圖像文件大小與原始文件大小相似,但不知何故存在缺陷.

I've noticed that the jpg files which are valid on the local machine - somehow become unreadable (corrupt files) on the server (where they were FTPd to). The image file size is similar to the original one, but somehow it is defected.

這是我用來將 jpg 寫入本地磁盤的代碼:

Here's a code I'm using to write the jpg to the LOCAL disk:

public static void writeJpeg(BufferedImage bfImg, String fileName, float quality) throws IOException{
FileImageOutputStream output = null;
try{
    Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = (ImageWriter)iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(quality);   // an integer between 0 and 1     
    File file = new File(fileName);
    output = new FileImageOutputStream(file);
    writer.setOutput(output);
    IIOImage image = new IIOImage(bfImg, null, null);
    writer.write(null, image, iwp);
}
finally{
    if (output != null){
        output.close();
    }
}

ftp 代碼很簡單:

JakartaFtpWrapper ftpClient = new JakartaFtpWrapper();
ftpClient.connectAndLogin(FTP_URL, FTP_USER, FTP_PASSWORD);
ftpClient.setPassiveMode(true);

File[] imageFiles = folder.listFiles()


  for (int j=0; j<imageFiles.length; j++){
        File imageFile = imageFiles[j];
        if (imageFile != null && imageFile.isFile() && (FileUtils.getFileSuffix(imageFile).equals("jpg") || FileUtils.getFileSuffix(imageFile).equals("png"))){ // upload only image files
            ftpClient.uploadFile(imageFile.getAbsolutePath(), imageFile.getName());
        }
    }

謝謝,然

推薦答案

服務(wù)器上正在運行什么?它是開箱即用"的 FTP 服務(wù)器還是您編寫的?

What's running on the server? Is it an "out of the box" FTP server or something you wrote?

圖像是二進制數(shù)據(jù).如果 JakartaFtpWrapper 提供了一些將 FTP 傳輸設(shè)置為二進制模式的選項,那么您應(yīng)該這樣做;我認為您的問題最可能的原因是在文本模式下處理傳輸?shù)哪J嘗試錯誤.如果您按字節(jié)比較小圖像,您應(yīng)該會看到在 0x0a 旁邊添加或刪除了回車 ((char) 0x0d == (char) 13).如果是這樣,那是你的問題.

Images are binary data. If JakartaFtpWrapper offers some option of putting the FTP transfer into binary mode, you should do that; I think the most likely cause of your problem is a bad default attempt to process the transfer in text mode. If you compare small images bytewise, you should see Carriage Returns ((char) 0x0d == (char) 13) being added or removed next to 0x0a's. If so, that's your problem.

這篇關(guān)于Java 使用 JakartaFtpWrapper 上傳 jpg - 使文件不可讀的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲一区影院 | 精品一区二区三区入口 | 国产精品国产精品国产专区不卡 | 国产一级在线 | 亚洲国产福利视频 | 台湾a级理论片在线观看 | 欧美成人精品激情在线观看 | 免费在线观看成年人视频 | 一区二区三区福利视频 | 99久久精品一区二区成人 | 91视视频在线观看入口直接观看 | 亚洲精精品 | 国产不卡在线观看 | 久久91av| 久久国产精品偷 | 免费视频二区 | 日韩影院在线 | 91视频观看 | 久久久久亚洲精品中文字幕 | 九色在线 | 日韩一区二区三区视频在线观看 | 国产欧美精品一区二区 | 成人精品一区二区三区中文字幕 | 一区二区三区欧美 | 日韩一级 | 久久91 | 久久久久国产一区二区三区四区 | 欧美一区二区三区视频在线播放 | 国产精品精品久久久 | 99久久99热这里只有精品 | 黄网免费 | 中文字幕在线一 | 国产一区二区三区四区五区3d | 欧美成人精品一区二区男人看 | 一区二区三区四区在线视频 | 一区二区三区精品视频 | 成人在线观看免费 | 国产欧美在线视频 | 欧美久久精品一级黑人c片 91免费在线视频 | 高清国产午夜精品久久久久久 | 91玖玖|