java如何下载文件
1. String fileUrl = "";
2. URL url = new URL(file) 得到URL对象
3. 由url得到输入流 InputStrea is = url.OpenStream();
4. 由输入流得到DataInputStrean对象 DataInputStream dataInputStream = new DataInputStream(is);
4 创建 FileOutputStream 对象 FileOutputStream fileOutputStream = new FileOutputStream(“要创建的文件路径”);
5. 然后创建缓冲区字节数组读取,读取完成后关闭
while ((len = dataInputStream.read(bytes)) > 0) {
fileOutputStream.write(bytes, 0, len);
}
dataInputStream.close();
fileOutputStream.close();