JDK7 ftp客户端开发有所改变

1.JDK 开发FTP客户端

 

package com.ftp.client;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import sun.net.ftp.FtpClient;
import sun.net.ftp.FtpProtocolException;

/**
 * 
 * @author LiuQing
 * @version 1.0
 * @see JDK7.0 FTP调用文件
 * @since
 */
public class FtpClientUtil {

	
	/**
	 * @param args
	 * @throws IOException 
	 * @throws FtpProtocolException 
	 */
	public static void main(String[] args) {
		
		OutputStream output = null;
		InputStream input = null;
		BufferedOutputStream buffOutput = null;
		try {
		    
			FtpClient ftpClient = FtpClient.create("localhost");
		    ftpClient.login("ftp","ftp".toCharArray());
			ftpClient.setBinaryType();
			input = ftpClient.getFileStream("oepe-indigo-installer-12.1.1.0.1.201203120349-12.1.1-linux32.bin");
			output = new FileOutputStream("d:\\oepe-indigo-installer-12.1.1.0.1.201203120349-12.1.1-linux32.bin");
			buffOutput = new BufferedOutputStream(output, 230);
			byte b[] = new byte[1024];
			
			while (true) {
				int length = input.read(b);
				if (length == -1) {
					break;
				}
				buffOutput.write(b, 0, length);
			}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			if (buffOutput != null) {
				try {
					buffOutput.close();
				} 
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (output != null) {
				try {
					output.close();
				} 
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (input != null) {
				try {
					input.close();
				} 
				catch (IOException e) {
					e.printStackTrace();
				}
			}
			
		}
		
	}

}
 

 

 

展开阅读全文

没有更多推荐了,返回首页