久久久久久久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.

我注意到在本地機(jī)器上有效的 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ù)器上正在運(yùn)行什么?它是開箱即用"的 FTP 服務(wù)器還是您編寫的?

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

圖像是二進(jìn)制數(shù)據(jù).如果 JakartaFtpWrapper 提供了一些將 FTP 傳輸設(shè)置為二進(jìn)制模式的選項,那么您應(yīng)該這樣做;我認(rèn)為您的問題最可能的原因是在文本模式下處理傳輸?shù)哪J(rèn)嘗試錯誤.如果您按字節(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(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美精品网站 | 羞羞视频免费观看 | 在线日韩不卡 | 国产午夜精品久久 | 成人免费观看视频 | 欧美一级在线 | www.国产91| 自拍视频网站 | 免费福利视频一区二区三区 | 伊人免费在线观看高清 | 九九九久久国产免费 | 国产麻豆一区二区三区 | 国产丝袜av| 亚洲日本视频 | 国产午夜精品久久久久免费视高清 | 久久亚洲精品国产精品紫薇 | 亚洲精品三级 | 午夜午夜精品一区二区三区文 | 久久99精品久久久久蜜桃tv | 亚洲第一女人av | 在线观看黄视频 | 国产精品一区二区三区在线 | 亚洲成人在线网 | 成人性生交大片免费看中文带字幕 | 免费高潮视频95在线观看网站 | 色av一区二区 | 国产精品精品视频一区二区三区 | 影音先锋中文字幕在线观看 | 久久91av| 久久精品一区二区三区四区 | 精品av| 琪琪午夜伦伦电影福利片 | 一区二区久久 | 久久国产精99精产国高潮 | 人人九九精| 黄色大片免费播放 | 国产一区三区在线 | 久久精品国产精品青草 | 亚洲乱码一区二区三区在线观看 | 日本五月婷婷 | 99pao成人国产永久免费视频 |