import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
public class HttpUtils {
public static void main(String[] args) {
String fromFile = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1502447858&di=d9cd99ad668028d3149cc343b9f64466&imgtype=jpg&er=1&src=http%3A%2F%2Fup.qqjia.com%2Fz%2Fface01%2Fface06%2Ffacejunyong%2Fjunyong04.jpg";
//String fromFile = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1501853243631&di=d98f0611d9c55513a817de3f90145ffa&imgtype=0&src=http%3A%2F%2Fupload.besoo.com%2Ffile%2F201610%2F22%2F0824478945908.jpg";
String toFile = "D:\\test\\11.jpg";
try {
URL website = new URL(fromFile);
Object obj = website.getContent();
System.out.println(obj.getClass().getName());
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(toFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
public class HttpUtils {
public static void main(String[] args) {
String fromFile = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1502447858&di=d9cd99ad668028d3149cc343b9f64466&imgtype=jpg&er=1&src=http%3A%2F%2Fup.qqjia.com%2Fz%2Fface01%2Fface06%2Ffacejunyong%2Fjunyong04.jpg";
//String fromFile = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1501853243631&di=d98f0611d9c55513a817de3f90145ffa&imgtype=0&src=http%3A%2F%2Fupload.besoo.com%2Ffile%2F201610%2F22%2F0824478945908.jpg";
String toFile = "D:\\test\\11.jpg";
try {
URL website = new URL(fromFile);
Object obj = website.getContent();
System.out.println(obj.getClass().getName());
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(toFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}