java从网络下载文件无需库

无需库

import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
public class CopyOfTest {
	public static void main(String[] args) throws MalformedURLException, IOException {
			//java从网络下载文件 无需库
			ReadableByteChannel readableByteChannel = Channels.newChannel(new URL("http://6.wjsou.com/uploads/filelist.txt").openStream());
			FileOutputStream fileOutputStream = new FileOutputStream("out.txt");
			fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
			fileOutputStream.close();	
			System.out.print("end");
	}
}

使用库Apache Commons IO   

猜你喜欢

转载自blog.csdn.net/chenhao0568/article/details/112718205