URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3*1000);
//防⽌屏蔽程序抓取⽽返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");        //得到输⼊流
InputStream();
}
/**
* 获取⽹络⽂件流中的内容,⼀次读⼀⾏,并将空格拆开,返回
* @param urlStr ⽹络⽂件url
* @return 返回pdf⽂件名和银⾏流⽔号映射集合
* @throws IOException IO异常
*/
public static Map<String,List<String>> downLoadFileContentFromUrl(String urlStr) throws IOException {        Map<String, List<String>> resultMap = new HashMap<>();
InputStream inputStream = null;
BufferedReader br = null;
try {
//得到输⼊流
inputStream = downLoadFromUrl(urlStr);
//构造⼀个BufferedReader类来读取⽂件
br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String line = null;
//使⽤readLine⽅法,⼀次读⼀⾏
while ((line = br.readLine()) != null) {
//通过空格进⾏切分
String[] split = line.split(" ");
if(split.length >= 2){
List<String> pdfNameList = (split[1]);
if(CollectionUtils.isEmpty(pdfNameList)){
pdfNameList = new ArrayList<>();
pdfNameList.add(split[0]);
resultMap.put(split[1],pdfNameList);
}else{
pdfNameList.add(split[0]);
}
}
}
} finally {
//关闭流
if(br != null){
br.close();
}
if(inputStream != null){
inputStream.close();
}
}
return resultMap;
}
/**
* 根据pdfName名称,从⽹络中获取Zip中的pdf⽂件InputStream
* @param urlStr Zip⽂件的下载url
* @param pdfName pdf名称
* @return 返回输⼊流
* @throws IOException IO异常
*/
public static InputStream downLoadZipFileFromUrl(String urlStr,String pdfName) throws IOException {        //声明字节输出数组
ByteArrayOutputStream byteOut = null;
ZipInputStream zipIn = null;
InputStream inputStream = null;
try {
//得到输⼊流
zipIn = new ZipInputStream(downLoadFromUrl(urlStr));
ZipEntry entry = null;
while ((entry = NextEntry()) != null) {
if(pdfName.Name())) {
//初始化字节输出数组
java streambyteOut = new ByteArrayOutputStream();

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。