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

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

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

問題描述

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

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 文件在服務器(它們被 FTP 傳輸到的位置)上不知何故變得不可讀(損壞的文件).圖像文件大小與原始文件大小相似,但不知何故存在缺陷.

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());
        }
    }

謝謝,然

推薦答案

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

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

圖像是二進制數據.如果 JakartaFtpWrapper 提供了一些將 FTP 傳輸設置為二進制模式的選項,那么您應該這樣做;我認為您的問題最可能的原因是在文本模式下處理傳輸的默認嘗試錯誤.如果您按字節比較小圖像,您應該會看到在 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.

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

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

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
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 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产欧美精品一区二区色综合 | 日本免费中文字幕 | 国产第一页在线 | 青青草网址 | 日韩成人精品 | 天堂资源av | 97自拍视频| 成人一级黄色片 | 黄色小视频在线观看 | 欧美精品乱码99久久蜜桃 | 一级黄色片视频 | 天堂中文字幕免费一区 | 欧洲av网站 | 国产精品伦子伦免费视频 | 国产精品成人国产乱 | a级黄色片| 国产福利视频在线观看 | 久久不雅视频 | 亚洲免费a | 婷婷伊人网 | av久草 | 国产精品福利一区 | 亚洲在线一区二区 | 国产伦精品一区二区三区视频我 | 精品黑人一区二区三区国语馆 | 日韩资源在线 | 日本精品视频 | 天堂中文字幕免费一区 | 永久免费看片在线播放 | 一级大片免费看 | 日韩精品区 | 日本精品视频在线观看 | 91看片在线观看 | 久久精品国产视频 | 在线观看h片 | 国产精品高清在线观看 | 国产一区二区在线看 | 亚洲一级特黄 | 黄色一级大片在线免费看国产一 | 久久99九九 | 中文av网站|