import java.net.HttpURLConnection;
import java.net.URL;
private void readNetFile(String fileUrl) {
// fileUrl为http或https链接
InputStream inputStream = null;
HttpURLConnection conn = null;
URL url;
try {
url = new URL(fileUrl);
conn = (HttpURLConnection) url.openConnection();
// 设置超时间为5秒
conn.setConnectTimeout(5 * 1000);
// 得到输入流
inputStream = conn.getInputStream();
//生成本地文件之类的省略了
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}