余米使用此代码,并尝试从服务器下载。这一种png格式PIC是代码如何使用FTPClient从FTP下载图像?
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import org.apache.commons.net.ftp.FTPClient;
public class NetTest {
public static void main(String[] args){
FTPClient client = new FTPClient();
OutputStream outStream;
try {
client.connect("server");
client.login("[email protected]", "pass");
String remoteFile = "Pages/page0001.png";
outStream = new FileOutputStream("C:\\asd.png");
client.retrieveFile(remoteFile, outStream);
} catch(IOException ioe) {
ioe.printStackTrace();
System.out.println("Error communicating with FTP server.");
} finally {
try {
client.disconnect();
} catch (IOException e) {
System.out.println("Problem disconnecting from FTP server");
}
}
}
}
这段代码给了我没有错误,但是当我打开图像它表明我无效图像。
下载图像的大小如何?它有效吗? –
下载的大小几乎相等。 –
如果文件大小很小打开并将检索到的文件看作文本 –