android下载文件报错!!急!

过儿丶 2017-01-13 10:36:26
电脑上浏览器和手机浏览器下载是可以的
但是用app里下载有问题
InputStream is = conn.getInputStream();
InputStream is = conn.getInputStream();这一行报filenotfoundexception异常
怎么办??
下载地址:http://192.168.2.201/training/android/download
...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
过儿丶 2017-01-13
  • 打赏
  • 举报
回复
刚刚用小米应用商城的地址测试。就不报filenotfound了。 是后台方式错了??该怎么解决?
过儿丶 2017-01-13
  • 打赏
  • 举报
回复
服务器那边的代码: @RestController @RequestMapping("/training/android") public class DownloadAction extends BaseMVCController{ @Value("${download.APK_NAME}") private String apkName;//"app-debug" @Value("${download.APK_PATH}") private String apkPath;//"D:/upload/apk/" @RequestMapping("/download") public void Download(){ /** 附件下载开始 */ response.setContentType("charset=UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" +apkName+".apk"); BufferedInputStream bis = null; BufferedOutputStream bos = null; OutputStream fos = null; InputStream fis = null; try { String filePath = apkPath +apkName+ ".apk"; File file = new File(filePath); if (!file.exists()) { System.out.println("不存在"); //压缩文件 return; } fis = new FileInputStream(filePath); bis = new BufferedInputStream(fis); fos = response.getOutputStream(); bos = new BufferedOutputStream(fos); int bytesRead = 0; byte[] buffer = new byte[5 * 1024]; while ((bytesRead = bis.read(buffer)) != -1) { bos.write(buffer, 0, bytesRead); } bos.flush(); } catch (Exception e) { } finally { try { bos.close(); fos.close(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } /** 附件下载结束 */ } }

80,360

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧