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

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

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

問(wèn)題描述

我一直在使用 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.

這是我用來(lái)將 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 代碼很簡(jiǎn)單:

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)行什么?它是開(kāi)箱即用"的 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)制模式的選項(xiàng),那么您應(yīng)該這樣做;我認(rèn)為您的問(wèn)題最可能的原因是在文本模式下處理傳輸?shù)哪J(rèn)嘗試錯(cuò)誤.如果您按字節(jié)比較小圖像,您應(yīng)該會(huì)看到在 0x0a 旁邊添加或刪除了回車 ((char) 0x0d == (char) 13).如果是這樣,那是你的問(wèn)題.

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 - 使文件不可讀的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 久久国产欧美日韩精品 | 日韩在线免费播放 | 久久亚洲国产精品 | 99精品久久久国产一区二区三 | www久久国产 | 黄网站免费观看 | 日本视频在线 | 二区在线视频 | 亚洲免费网 | 国产一区二区三区四区三区四 | 亚洲毛片 | 日韩成人在线播放 | 国产在线精品一区 | 欧美大片一区 | 一区二区精品 | 国产成人精品一区二区 | 国产91亚洲精品一区二区三区 | 在线观看视频一区二区三区 | 日韩欧美三区 | 日韩中文字幕视频 | 国产激情一区二区三区 | 国产精品视频导航 | 99re6在线 | 国产精品久久久久一区二区三区 | 欧美一区二区三区久久精品 | 伊人精品久久久久77777 | 精品视频一区二区 | www成人免费 | 国产美女在线看 | 国产激情免费视频 | 午夜寂寞影院在线观看 | 成人免费一区二区三区视频网站 | 中文字幕免费视频 | 日韩精品免费在线观看 | 91视频进入| 欧美一区2区三区3区公司 | 国产高潮好爽受不了了夜夜做 | 一区二区av | 中文字幕 视频一区 | 午夜影院在线观看视频 | 中文字幕日韩欧美一区二区三区 |