Flutter开发App的未来及其在各行业的应用潜力分析
763
2022-12-24
从Springboot项目中-文件的具体过程
最近在做一个临时的项目,APP端在检测到程序有更新时,需要去后台-新的安装包。具体过程FPCKD如下:
controller层:
/**
* -app
* @param response
*/
http:// @RequestMapping("downApp")
@ResponseBody
public void Download(HttpServletResponse response) {
String fileName ="wuye.apk";
String result = FileUtil.downloadFile(response, fileName);
log.info("app包-结果:",result);
}
工具类:
public class FileUtil {
public static String downloadFile(HttpServletResponse response, String fileName) {
File path =null;
response.setHeader("content-type","application/octet-stream");
response.setContentType("application/octet-stream");
try {
response.setHeader("Content-Disposition","attachment;filename=" + java.nhttp://et.URLEncoder.encode(fileName,"UTF-8"));
}catch (UnsupportedEncodingException e2) {
e2.printStackTrace();
}
byte[] buff =new byte[1024];
BufferedInputStream bis =null;
OutputStream os =null;
try {
path =new File(ResourceUtils.getURL("classpath:").getPath());
os = response.getOutputStream();
bis =new BufferedInputStream(new FileInputStream(new File(path +"/doc/" + fileName)));
int i = bis.read(buff);
while (i != -1) {
os.write(buff,0, buff.length);
os.flush();
i = bis.read(buff);
}
}catch (FileNotFoundException e1) {
//e1.getMessage()+"系统找不到指定的文件";
return "系统找不到指定的文件";
}catch (IOException e) {
e.printStackTrace();
}finally {
if (bis !=null) {
try {
bis.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
return "success";
}
访问:http://127.0.0.1:8081/ymd/downApp 文件就-下来了,本方法借鉴了 网络上的一些文章
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~