目录:
- 一、以流的方式下载
- 二、下载本地文件
- 三、下载网络文件
- 四、在线打开的方式
- 五、将文件转换成base64
- 六、将MultipartFile转换为File
- 七、项目实战
一、以流的方式下载
public HttpServletResponse download(String path, HttpServletResponse response) { try { // path是指欲下载的文件的路径。 File file = new File(path); // 取得文件名。 String filename = file.getName(); // 取得文件的后缀名。 String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase(); // 以流的形式下载文件。 InputStream fis = new BufferedInputStream(new FileInputStream(path)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); // 清空response response.reset(); // 设置response的Header response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes())); response.addHeader("Content-Length", "" + file.length()); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); response.setContentType("application/octet-stream"); toClient.write(buffer); toClient.flush(); toClient.close(); } catch (IOException ex) { ex.printStackTrace(); } return response; }二、下载本地文件
public void downloadLocal(HttpServletResponse response) throws FileNotFoundException { // 下载本地文件 String fileName = "Operator.doc".toString(); // 文件的默认保存名 // 读到流中 InputStream inStream = new FileInputStream("c:/Operator.doc");// 文件的存放路径 // 设置输出的格式 response.reset(); response.setContentType("bin"); response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); // 循环取出流中的数据 byte[] b = new byte[100]; int len; try { while ((len = inStream.read(b)) > 0) response.getOutputStream().write(b, 0, len); inStream.close(); } catch (IOException e) { e.printStackTrace(); } }三、下载网络文件
public void downloadNet(HttpServletResponse response) throws MalformedURLException { // 下载网络文件 int bytesum = 0; int byteread = 0; URL url = new URL("windine.blogdriver.com/logo.gif"); try { URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); FileOutputStream fs = new FileOutputStream("c:/abc.gif"); byte[] buffer = new byte[1204]; int length; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; System.out.println(bytesum); fs.write(buffer, 0, byteread); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }四、在线打开的方式
public void downLoad(String filePath, HttpServletResponse response, boolean isOnLine) throws Exception { File f = new File(filePath); if (!f.exists()) { response.sendError(404, "File not found!"); return; } BufferedInputStream br = new BufferedInputStream(new FileInputStream(f)); byte[] buf = new byte[1024]; int len = 0; response.reset(); // 非常重要 if (isOnLine) { // 在线打开方式 URL u = new URL("file:///" + filePath); response.setContentType(u.openConnection().getContentType()); response.setHeader("Content-Disposition", "inline; filename=" + f.getName()); // 文件名应该编码成UTF-8 } else { // 纯下载方式 response.setContentType("application/x-msdownload"); response.setHeader("Content-Disposition", "attachment; filename=" + f.getName()); } OutputStream out = response.getOutputStream(); while ((len = br.read(buf)) > 0) out.write(buf, 0, len); br.close(); out.close(); }五、将文件转换成base64
/** * 将文件转为base64 */ public static String getBase64FromFile(File file) throws IOException { FileInputStream in = null; ByteArrayOutputStream out = null; try { in = new FileInputStream(file); out = new ByteArrayOutputStream(); int read = 0; byte[] buffer = new byte[1024]; while ((read = in.read(buffer, 0, 1024)) != -1) { out.write(buffer, 0, read); } return Base64.getEncoder().encodeToString(out.toByteArray()); } catch (IOException e) { throw e; } finally { if (in != null) { in.close(); } if (out != null){ out.close(); } } }六、将MultipartFile转换为File
/** * 将MultipartFile转换为File */ public static File MultipartFileToFile(MultipartFile multiFile) throws IOException { String fileName = multiFile.getOriginalFilename(); String prefix = fileName.substring(fileName.lastIndexOf(".")); InputStream in = null; OutputStream out = null; try { File file = File.createTempFile(fileName, prefix); out = new FileOutputStream(file); in = multiFile.getInputStream(); int read = 0; byte[] buffer = new byte[1024]; while ((read = in.read(buffer, 0, 1024)) != -1) { out.write(buffer, 0, read); } return file; } catch (Exception e) { throw e; }finally { if (in != null){ in.close(); } if (out != null){ out.close(); } } }七、项目实战
FileInputStream fileInputStream = new FileInputStream("C:/Users/Admin/Downloads/test.docx"); response.reset(); response.setContentType("application/octet-stream"); String resultFileName = URLEncoder.encode("test" + task_id + ".docx", "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + resultFileName + ";" + "filename*=utf-8''" + resultFileName); //URLConnection conn = url.openConnection(); //InputStream inStream = conn.getInputStream(); // 循环取出流中的数据 byte[] b = new byte[100]; int len; try { while ((len = fileInputStream.read(b)) > 0) response.getOutputStream().write(b, 0, len); fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } response.flushBuffer();最终成功将文件下载下来了。
根据最近的行业调研和招聘数据,AI的发展确实对Java工程师提出了新挑战,但也带来了明确的转型机遇。其现状可概括为:市场分化明显,初级岗位收缩,但“Java+AI”的复合型人才需求正在崛起。
🛠️ 给Java工程师的转型行动建议
转变核心角色定位
- 目标应从“业务代码实现者”转向 “智能系统构建者” 或 “AI与业务的中枢架构师” 。这意味着你的核心价值在于设计能容纳AI能力的系统、确保其稳定高效运行,并深刻理解业务以找到AI的最佳落地场景
构建“Java + AI”双技能栈:
巩固Java深度:深入JVM性能调优、分布式系统设计,这是你区别于纯AI算法工程师的基石。
学习AI应用层技术:不必从零开始研究算法。优先学习如何使用AI工具和框架,例如:
Prompt Engineering(提示词工程):高效驱动大模型的关键技能。
AI应用框架:学习 LangChain4J、Spring AI 等,掌握在Java中集成和调度AI模型的方法。
向量数据库:了解Milvus等,这是构建AI语义搜索、推荐系统的基础。
从“用AI辅助编程”开始实践
- 立即在日常工作中使用GitHub Copilot等工具,亲身体验其如何改变工作流。同时,警惕过度依赖,将节约出的时间用于更高层的设计和优化工作。
选择垂直领域深耕
- 将你的Java经验与某个行业(如金融、医疗、工业物联网)结合,成为既懂行业业务又懂AI落地解决方案的专家,这会形成强大的竞争壁垒。
因此捕获AI,掌握技术是关键,让AI成为我们最便利的工具.
一定要把现有的技术和大模型结合起来,而不是抛弃你们现有技术!掌握AI能力的Java工程师比纯Java岗要吃香的多。
即使现在裁员、降薪、团队解散的比比皆是……但后续的趋势一定是AI应用落地!大模型方向才是实现职业升级、提升薪资待遇的绝佳机遇!
如何学习AGI大模型?
作为一名热心肠的互联网老兵,我决定把宝贵的AI知识分享给大家。 至于能学习到多少就看你的学习毅力和能力了 。我已将重要的AI大模型资料包括AI大模型入门学习思维导图、精品AI大模型学习书籍手册、视频教程、实战学习等录播视频免费分享出来。
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
2025最新版CSDN大礼包:《AGI大模型学习资源包》免费分享**
一、2025最新大模型学习路线
一个明确的学习路线可以帮助新人了解从哪里开始,按照什么顺序学习,以及需要掌握哪些知识点。大模型领域涉及的知识点非常广泛,没有明确的学习路线可能会导致新人感到迷茫,不知道应该专注于哪些内容。
我们把学习路线分成L1到L4四个阶段,一步步带你从入门到进阶,从理论到实战。
L1级别:AI大模型时代的华丽登场
L1阶段:我们会去了解大模型的基础知识,以及大模型在各个行业的应用和分析;学习理解大模型的核心原理,关键技术,以及大模型应用场景;通过理论原理结合多个项目实战,从提示工程基础到提示工程进阶,掌握Prompt提示工程。
L2级别:AI大模型RAG应用开发工程
L2阶段是我们的AI大模型RAG应用开发工程,我们会去学习RAG检索增强生成:包括Naive RAG、Advanced-RAG以及RAG性能评估,还有GraphRAG在内的多个RAG热门项目的分析。
L3级别:大模型Agent应用架构进阶实践
L3阶段:大模型Agent应用架构进阶实现,我们会去学习LangChain、 LIamaIndex框架,也会学习到AutoGPT、 MetaGPT等多Agent系统,打造我们自己的Agent智能体;同时还可以学习到包括Coze、Dify在内的可视化工具的使用。
L4级别:大模型微调与私有化部署
L4阶段:大模型的微调和私有化部署,我们会更加深入的探讨Transformer架构,学习大模型的微调技术,利用DeepSpeed、Lamam Factory等工具快速进行模型微调;并通过Ollama、vLLM等推理部署框架,实现模型的快速部署。
整个大模型学习路线L1主要是对大模型的理论基础、生态以及提示词他的一个学习掌握;而L3 L4更多的是通过项目实战来掌握大模型的应用开发,针对以上大模型的学习路线我们也整理了对应的学习视频教程,和配套的学习资料。
二、大模型经典PDF书籍
书籍和学习文档资料是学习大模型过程中必不可少的,我们精选了一系列深入探讨大模型技术的书籍和学习文档,它们由领域内的顶尖专家撰写,内容全面、深入、详尽,为你学习大模型提供坚实的理论基础。(书籍含电子版PDF)
三、大模型视频教程
对于很多自学或者没有基础的同学来说,书籍这些纯文字类的学习教材会觉得比较晦涩难以理解,因此,我们提供了丰富的大模型视频教程,以动态、形象的方式展示技术概念,帮助你更快、更轻松地掌握核心知识。
四、大模型项目实战
学以致用,当你的理论知识积累到一定程度,就需要通过项目实战,在实际操作中检验和巩固你所学到的知识,同时为你找工作和职业发展打下坚实的基础。
五、大模型面试题
面试不仅是技术的较量,更需要充分的准备。
在你已经掌握了大模型技术之后,就需要开始准备面试,我们将提供精心整理的大模型面试题库,涵盖当前面试中可能遇到的各种技术问题,让你在面试中游刃有余。
因篇幅有限,仅展示部分资料,需要点击下方链接即可前往获取
2025最新版CSDN大礼包:《AGI大模型学习资源包》免费分享