Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload and download JAVA

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to upload and download JAVA". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Public class FileUtil {/ * * Description: copy file * * [@ param] (https://my.oschina.net/u/2303379) srcFile upload file * [@ param] (https://my.oschina.net/u/2303379) filePath save file address * [@ return] (https://my.oschina.net/u/) 556800) * [@ date] (https://my.oschina.net/u/2504391) 2019-1-18 * / public static void copyFile (MultipartFile srcFile) String filePath) throws Exception {/ / determine whether to upload a file if (srcFile = = null | | srcFile.isEmpty () | | StringUtils.isBlank (filePath)) {throw new NullPointerException ("upload file is empty") } InputStream inputStream = srcFile.getInputStream (); File file = new File (filePath); if (! file.exists ()) {file.getParentFile (). Mkdirs ();} FileOutputStream outputStream = new FileOutputStream (file); try {IOUtils.copy (inputStream, outputStream) } finally {IOUtils.closeQuietly (inputStream); IOUtils.closeQuietly (outputStream) } / * Description: download PDF * * [@ param] locally (https://my.oschina.net/u/2303379) fileName * file name * @ return * @ date * / public static boolean copyPdf (HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) {File file = new File (filePath + fileName) / / if the file does not exist, return if (! file.exists ()) {return false;} BufferedInputStream inputStream = null; BufferedOutputStream outputStream = null; try {setDownLoadResponseHeader (request, response, fileName); inputStream = new BufferedInputStream (new FileInputStream (file)); outputStream = new BufferedOutputStream (response.getOutputStream ()); IOUtils.copy (inputStream, outputStream) } catch (IOException e) {e.printStackTrace ();} finally {try {if (inputStream! = null) {inputStream.close ();} if (outputStream! = null) {outputStream.close () }} catch (IOException e) {e.printStackTrace ();}} return true;} "how to upload and download JAVA" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report