try {
// 1.以要下载文件的 URL 为参数创建 URL 对象
URL url = new URL(sfPath);
// 2.打开连接下载文件
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
String filename = sfPath.substring(sfPath.lastIndexOf("/") + 1);
File file = new File(sfFilePath);
if (!file.exists()) {
file.mkdir();
}
File sfFile = new File(sfFilePath + filename);
sfFile.createNewFile();
OutputStream os = new FileOutputStream(sfFile);
byte[] buff = new byte[1024 * 4];
while (is.read(buff) != -1) {
os.write(buff);
}
is.close();
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
为什么下载文本内容不全,求大神指导下。。。。。。。。。