在linux发布,无法下载图片

ice9ying ice9ying 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在本地测试,下载网络图片到本地没有问题,但是发布到linux,却无法下载,但也没有报错。代码如下
  
URL url = new URL("网络图片地址");
// 打开连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
connection.setConnectTimeout(5 * 1000);
InputStream inputStream = connection.getInputStream();

byte[] bs = new byte[1024];
int len;
File sf=new File(exp_path); // /home/
if(!sf.exists()){
sf.mkdirs();
}
OutputStream os = new FileOutputStream(sf.getPath()+"\\123.png");
// 读取
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}

os.flush();
// 关闭
os.close();
inputStream.close();


刚转做java,求各位高手相助
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
ice9ying
Web 开发 81,108 成员 341,721 内容