本文示例工程下载:https://files.cnblogs.com/files/xiandedanteng/WebFileDownload20191026.rar

制作一个Webapp,让其中一个网页提供下载链接,以使用户能下载本地文件或是临时生成的文件,这些都不是难事,网上也有很多既存的解决方案。

但是,这个问题难点在,但生成文件过大时,产生java.lang.OutOfMemoryError异常怎么办?有人提出修改JVM内存参数,如-Xms<min>m -Xmx<max>m方式,但终究是治标不治本的方法,如果下载数据量又超过设定的上限呢?

其实问题的本质是:在为大数据生成准备过程中,大量对象产生了来不及释放,因为还需要在接下来的步骤中使用,所以驻留在内存中,内存越积越多,终究导致java.lang.OutOfMemoryError异常。举个例子来说,有个emp表,存储员工的id姓名年龄等,当只有千百条时,取出结果集转成链表再写入csv文件自然没什么问题,但如果数据越来越多,还是结果集放链表里又来不及释放,总有内存不够的时候。

  1. 2019-10-25 14:43:05.518 ERROR 40016 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause
  2.  
  3. java.lang.OutOfMemoryError: GC overhead limit exceeded
  4. at java.lang.Integer.toString(Unknown Source) ~[na:1.8.0_201]
  5. at java.lang.String.valueOf(Unknown Source) ~[na:1.8.0_201]
  6. at com.example.demo.CsvUtil.exportBigCsv(CsvUtil.java:78) ~[classes/:na]
  7. at com.example.demo.SpringBootWeb1Application.downloadBigCsvFile(SpringBootWeb1Application.java:141) ~[classes/:na]
  8. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
  9. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_201]
  10. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_201]
  11. at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_201]
  12. at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  13. at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  14. at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  15. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  16. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  17. at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  18. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  19. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  20. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  21. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  22. at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  23. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  24. at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  25. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  26. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  27. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.24.jar:9.0.24]
  28. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  29. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  30. at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  31. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  32. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  33. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.24.jar:9.0.24]
  34. at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]
  35. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118) ~[spring-web-5.1.9.RELEASE.jar:5.1.9.RELEASE]

要解决这个问题,就得耐下心来,将整体读整体写改成分批读分批写(分批方案和分页方案类似,诸位可自行寻找合适自己DB的DB dialect),最后再下载。

示例页面:

  1. <!DOCTYPE html>
  2. <html lang="utf-8">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  4. <head>
  5. <title>happy go lucky</title>
  6. </head>
  7.  
  8. <body>
  9. <h2>文件下载测试</h2>
  10. <hr/>
  11. <ol>
  12. <li><a href="/dldLocalFile">下载本地文件dld.rar</a></li>
  13. <li><a href="/dldGeneratedFile/100">下载生成百行CSV文件</a></li>
  14. <li><a href="/dldGeneratedFile/100000000">下载生成亿行CSV文件</a></li>
  15. <li><a href="/dldGeneratedFile2/10000000">下载生成千万行CSV文件 可能 出现java.lang.OutOfMemoryError: GC overhead limit exceeded</a></li>
  16. <li><a href="/dldGeneratedFile3/10000000">下载生成千万行CSV文件 不会可能 出现java.lang.OutOfMemoryError: GC overhead limit exceeded</a></li>
  17. </ol>
  18. </body>
  19. </html>
  20. <script type="text/javascript">
  21. <!--
  22. // 脚本
  23. //-->
  24. </script>

控制类:

  1. package com.example.demo;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.net.URLDecoder;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10.  
  11. import javax.servlet.ServletOutputStream;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. import org.apache.log4j.Logger;
  16. import org.springframework.boot.SpringApplication;
  17. import org.springframework.boot.autoconfigure.SpringBootApplication;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.web.bind.annotation.PathVariable;
  20. import org.springframework.web.bind.annotation.RequestMapping;
  21.  
  22. @Controller
  23. @SpringBootApplication
  24. public class WebFileDownloadApplication {
  25. private static Logger logger = Logger.getLogger(WebFileDownloadApplication.class);
  26.  
  27. public static void main(String[] args) {
  28. SpringApplication.run(WebFileDownloadApplication.class, args);
  29. }
  30.  
  31. @RequestMapping("/")
  32. public String index() {
  33. logger.info("进入index页");
  34. return "index.html";
  35. }
  36.  
  37. @RequestMapping("/dldLocalFile")
  38. public void downloadLocalFile(HttpServletResponse res, HttpServletRequest req) throws Exception {
  39. logger.info("下载本地文件");
  40.  
  41. String localFilename = "dld.rar";
  42. String localFilepath = getClass().getResource("/static/" + localFilename).getPath();
  43.  
  44. res.setContentType("multipart/form-data");
  45. res.setCharacterEncoding("UTF-8");
  46. res.setContentType("text/html");
  47.  
  48. String userAgent = req.getHeader("User-Agent");
  49. if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
  50. // IE Core
  51. localFilename = java.net.URLEncoder.encode(localFilename, "UTF-8");
  52. } else {
  53. // Non-IE Core
  54. localFilename = new String((localFilename).getBytes("UTF-8"), "ISO-8859-1");
  55. }
  56. res.setHeader("Content-Disposition", "attachment;fileName=" + localFilename);
  57.  
  58. localFilepath = URLDecoder.decode(localFilepath, "UTF-8");
  59. FileInputStream instream = new FileInputStream(localFilepath);
  60. ServletOutputStream outstream = res.getOutputStream();
  61. int b = 0;
  62. byte[] buffer = new byte[1024];
  63. while ((b = instream.read(buffer)) != -1) {
  64. outstream.write(buffer, 0, b);
  65. }
  66. instream.close();
  67.  
  68. if (outstream != null) {
  69. outstream.flush();
  70. outstream.close();
  71. }
  72. }
  73.  
  74. @RequestMapping("/dldGeneratedFile/{count}")
  75. public void downloadGeneratedCsvFile(HttpServletResponse res, HttpServletRequest req,@PathVariable String count) throws Exception {
  76. logger.info("Start downloadGeneratedCsvFile");
  77.  
  78. SimpleDateFormat dfs = new SimpleDateFormat("yyyyMMddHHmmss");
  79. Date time = new Date();
  80. String tStamp = dfs.format(time);
  81.  
  82. String localFilename = tStamp+".csv";
  83. String path=req.getSession().getServletContext().getRealPath("/");
  84. String localFilepath = path+localFilename;
  85. logger.info("准备生成的本地路径文件名="+localFilepath);
  86.  
  87. res.setContentType("multipart/form-data");
  88. res.setCharacterEncoding("UTF-8");
  89. res.setContentType("text/html");
  90.  
  91. String userAgent = req.getHeader("User-Agent");
  92. if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
  93. // IE Core
  94. localFilename = java.net.URLEncoder.encode(localFilename, "UTF-8");
  95. } else {
  96. // Non-IE Core
  97. localFilename = new String((localFilename).getBytes("UTF-8"), "ISO-8859-1");
  98. }
  99. res.setHeader("Content-Disposition", "attachment;fileName=" + localFilename);
  100.  
  101. localFilepath = URLDecoder.decode(localFilepath, "UTF-8");
  102.  
  103. List<String> dataList=new ArrayList<String>();
  104. for(int i=0;i<100;i++) {
  105. dataList.add(String.valueOf(i));
  106. }
  107.  
  108. File file=new File(localFilepath);
  109. CsvUtil.generateCsv(file,Integer.parseInt(count));
  110. logger.info("已经生成文件:"+localFilepath);
  111.  
  112. FileInputStream instream = new FileInputStream(localFilepath);
  113. ServletOutputStream outstream = res.getOutputStream();
  114. int b = 0;
  115. byte[] buffer = new byte[1024];
  116. while ((b = instream.read(buffer)) != -1) {
  117. outstream.write(buffer, 0, b);
  118. }
  119. instream.close();
  120.  
  121. if (outstream != null) {
  122. outstream.flush();
  123. outstream.close();
  124. boolean isDeleted=file.delete();
  125. if(isDeleted) {
  126. logger.info("已经删除文件:"+localFilepath);
  127. }
  128. }
  129. }
  130.  
  131. @RequestMapping("/dldGeneratedFile2/{count}")
  132. public void downloadGeneratedCsvFile2(HttpServletResponse res, HttpServletRequest req,@PathVariable String count) throws Exception {
  133. logger.info("Start downloadGeneratedCsvFile2");
  134.  
  135. SimpleDateFormat dfs = new SimpleDateFormat("yyyyMMddHHmmss");
  136. Date time = new Date();
  137. String tStamp = dfs.format(time);
  138.  
  139. String localFilename = tStamp+".csv";
  140. String path=req.getSession().getServletContext().getRealPath("/");
  141. String localFilepath = path+localFilename;
  142. logger.info("准备生成的本地路径文件名="+localFilepath);
  143.  
  144. res.setContentType("multipart/form-data");
  145. res.setCharacterEncoding("UTF-8");
  146. res.setContentType("text/html");
  147.  
  148. String userAgent = req.getHeader("User-Agent");
  149. if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
  150. // IE Core
  151. localFilename = java.net.URLEncoder.encode(localFilename, "UTF-8");
  152. } else {
  153. // Non-IE Core
  154. localFilename = new String((localFilename).getBytes("UTF-8"), "ISO-8859-1");
  155. }
  156. res.setHeader("Content-Disposition", "attachment;fileName=" + localFilename);
  157.  
  158. localFilepath = URLDecoder.decode(localFilepath, "UTF-8");
  159.  
  160. List<String> dataList=new ArrayList<String>();
  161. for(int i=0;i<100;i++) {
  162. dataList.add(String.valueOf(i));
  163. }
  164.  
  165. File file=new File(localFilepath);
  166. CsvUtil.generateCsv2(file,Integer.parseInt(count));
  167. logger.info("已经生成文件:"+localFilepath);
  168.  
  169. FileInputStream instream = new FileInputStream(localFilepath);
  170. ServletOutputStream outstream = res.getOutputStream();
  171. int b = 0;
  172. byte[] buffer = new byte[1024];
  173. while ((b = instream.read(buffer)) != -1) {
  174. outstream.write(buffer, 0, b);
  175. }
  176. instream.close();
  177.  
  178. if (outstream != null) {
  179. outstream.flush();
  180. outstream.close();
  181. boolean isDeleted=file.delete();
  182. if(isDeleted) {
  183. logger.info("已经删除文件:"+localFilepath);
  184. }
  185. }
  186. }
  187.  
  188. @RequestMapping("/dldGeneratedFile3/{count}")
  189. public void downloadGeneratedCsvFile3(HttpServletResponse res, HttpServletRequest req,@PathVariable String count) throws Exception {
  190. logger.info("Start downloadGeneratedCsvFile3");
  191.  
  192. SimpleDateFormat dfs = new SimpleDateFormat("yyyyMMddHHmmss");
  193. Date time = new Date();
  194. String tStamp = dfs.format(time);
  195.  
  196. String localFilename = tStamp+".csv";
  197. String path=req.getSession().getServletContext().getRealPath("/");
  198. String localFilepath = path+localFilename;
  199. logger.info("准备生成的本地路径文件名="+localFilepath);
  200.  
  201. res.setContentType("multipart/form-data");
  202. res.setCharacterEncoding("UTF-8");
  203. res.setContentType("text/html");
  204.  
  205. String userAgent = req.getHeader("User-Agent");
  206. if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
  207. // IE Core
  208. localFilename = java.net.URLEncoder.encode(localFilename, "UTF-8");
  209. } else {
  210. // Non-IE Core
  211. localFilename = new String((localFilename).getBytes("UTF-8"), "ISO-8859-1");
  212. }
  213. res.setHeader("Content-Disposition", "attachment;fileName=" + localFilename);
  214.  
  215. localFilepath = URLDecoder.decode(localFilepath, "UTF-8");
  216.  
  217. List<String> dataList=new ArrayList<String>();
  218. for(int i=0;i<100;i++) {
  219. dataList.add(String.valueOf(i));
  220. }
  221.  
  222. File file=new File(localFilepath);
  223. CsvUtil.generateCsv3(file,Integer.parseInt(count));
  224. logger.info("已经生成文件:"+localFilepath);
  225.  
  226. FileInputStream instream = new FileInputStream(localFilepath);
  227. ServletOutputStream outstream = res.getOutputStream();
  228. int b = 0;
  229. byte[] buffer = new byte[1024];
  230. while ((b = instream.read(buffer)) != -1) {
  231. outstream.write(buffer, 0, b);
  232. }
  233. instream.close();
  234.  
  235. if (outstream != null) {
  236. outstream.flush();
  237. outstream.close();
  238. boolean isDeleted=file.delete();
  239. if(isDeleted) {
  240. logger.info("已经删除文件:"+localFilepath);
  241. }
  242. }
  243. }
  244. }

数据生成类:

  1. package com.example.demo;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import org.apache.log4j.Logger;
  10.  
  11. public class CsvUtil {
  12. private static Logger logger = Logger.getLogger(CsvUtil.class);
  13.  
  14. // 这种方式不会内存溢出,因为创建的数组对象用于写完文件后在一个循环结束就释放了
  15. public static boolean generateCsv(File file,int rowCount) {
  16. try {
  17. FileWriter fileWriter =new FileWriter(file, true);
  18.  
  19. for(int j=0;j<rowCount;j++) {
  20. int lineNo=j;
  21.  
  22. String[] arr=new String[20];
  23.  
  24. for(int k=0;k<arr.length;k++) {
  25. arr[k]=String.valueOf(k);
  26. }
  27.  
  28. String info=String.valueOf(lineNo)+","+String.join(",", arr)+System.getProperty("line.separator");
  29. fileWriter.write(info);
  30. }
  31.  
  32. fileWriter.flush();
  33. fileWriter.close();
  34. } catch (IOException e) {
  35. e.printStackTrace();
  36. }
  37.  
  38. return true;
  39. }
  40.  
  41. // 这种方式因为生成一个大list,容易造成内存驻留过多而溢出
  42. public static boolean generateCsv2(File file,int rowCount) {
  43. try {
  44. // 先模拟访问数据库创建集合,当数据量大时会出现outofmemory异常
  45. List<String[]> list=new ArrayList<String[]>();
  46. for(int i=0;i<rowCount;i++) {
  47. String[] arr=new String[20];
  48. for(int k=0;k<arr.length;k++) {
  49. arr[k]=String.valueOf(k);
  50. }
  51.  
  52. list.add(arr);
  53. }
  54.  
  55. // 再将集合写文件
  56. FileWriter fileWriter =new FileWriter(file, true);
  57.  
  58. int index=0;
  59. for(String[] arr:list) {
  60. index++;
  61.  
  62. String info=String.valueOf(index)+","+String.join(",", arr)+System.getProperty("line.separator");
  63. fileWriter.write(info);
  64. }
  65.  
  66. fileWriter.flush();
  67. fileWriter.close();
  68. } catch (IOException e) {
  69. e.printStackTrace();
  70. }
  71.  
  72. return true;
  73. }
  74.  
  75. // 这种方式改成分批写入文件方式,以规避内存溢出
  76. public static boolean generateCsv3(File file,int rowCount) {
  77. logger.info("generateCsv3");
  78.  
  79. try {
  80. final int LinesOnceTime=10000;
  81. int count=rowCount/LinesOnceTime;
  82.  
  83. for(int i=0;i<count;i++) {
  84. // 再将集合写文件
  85. FileWriter fileWriter =new FileWriter(file, true);
  86.  
  87. List<String[]> list=new ArrayList<String[]>();
  88.  
  89. // 这回list被限制在了LinesOnceTime件,这一步代表着从数据库分批取,oracle有townum支持,mysql有limit支持
  90. for(int j=0;j<LinesOnceTime;j++) {
  91. String[] arr=new String[20];
  92.  
  93. for(int k=0;k<arr.length;k++) {
  94. arr[k]=String.valueOf(k);
  95. }
  96.  
  97. list.add(arr);
  98. }
  99.  
  100. int index=0;
  101. for(String[] arr:list) {
  102. index++;
  103.  
  104. int lineNo=i*LinesOnceTime+index;
  105. String info=String.valueOf(lineNo)+","+String.join(",", arr)+System.getProperty("line.separator");
  106. fileWriter.write(info);
  107. }
  108.  
  109. fileWriter.flush();
  110. fileWriter.close();
  111. }
  112. } catch (IOException e) {
  113. e.printStackTrace();
  114. }
  115.  
  116. return true;
  117. }
  118. }

续篇请看:https://www.cnblogs.com/xiandedanteng/p/11747855.html

--END-- 2019年10月26日14:49:02

[SpringBoot/SpringMVC]从Webapp下载一个大文件出现java.lang.OutOfMemoryError: GC overhead limit exceeded怎么办?的更多相关文章

  1. 正确使用MySQL JDBC setFetchSize()方法解决JDBC处理大结果集 java.lang.OutOfMemoryError: Java heap space

    昨天在项目中需要对日志的查询结果进行导出功能. 日志导出功能的实现是这样的,输入查询条件,然后对查询结果进行导出.由于日志数据量比较大.多的时候,有上亿条记录. 之前的解决方案都是多次查询,然后使用l ...

  2. 导入到eclipse里的工程挺大的,然后就一直报: An internal error occurred during: "Building workspace". GC overhead limit exceeded 这个错误。

    解决方法: 原因是Eclipse默认配置内存太小需要更改Eclipse安装文件夹下的eclipse.ini文件. Eclipse.ini默认文件如下: 修改如下: -Xms1024m -Xmx2048 ...

  3. Facebook图片存储系统Haystack——存小文件,本质上是将多个小文件合并为一个大文件来降低io次数,meta data里存偏移量

    转自:http://yanyiwu.com/work/2015/01/04/Haystack.html 一篇14页的论文Facebook-Haystack, 看完之后我的印象里就四句话: 因为[传统文 ...

  4. spring-framework-3.2.4.RELEASE 综合hibernate-release-4.3.5.Final一个错误Caused by: java.lang.NoClassDefFound

    LZ一体化的今天spring-framework-3.2.4.RELEASE 综合hibernate-release-4.3.5.Final一个错误Caused by: java.lang.NoCla ...

  5. 精讲RestTemplate第6篇-文件上传下载与大文件流式下载

    本文是精讲RestTemplate第6篇,前篇的blog访问地址如下: 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用 精讲RestTemplate第2篇-多种底层H ...

  6. mac下载百度云盘大文件及断点续传的方法

    问题 作为资源共享平台, 百度云做的还是很出色的, "xxx site:pan.baidu.com"就可以找到很丰富的资源. 然而, 下载百度云上的文件就略蛋疼了. 早在12年的时 ...

  7. 推荐一个大文件查找工具---WizTree

    DB备份.dump.电影等文件多了以后,经常遇到磁盘空间不够用的情况,日积月累本来清晰的目录结构找起来也很费劲,尤其是要查找删除无用的大文件.windows本身那差劲的搜索功能就不提了,从搜索引擎上查 ...

  8. 判断大文件是否上传成功(一个大文件上传到ftp,判断是否上传完成)

    大文件上传ftp,不知道有没有上传完成,如果没有上传完成另一个程序去下载这个文件,导致下载不完整. 判断一个文件是否上传完成的方法: /** * 间隔一段时间去计算文件的长度来判断文件是否写入完成 * ...

  9. python如何打开一个大文件?

    with open('a.csv','r') as f: for i in f: print(i) while True: a = f.readline() if not a: break f.rea ...

随机推荐

  1. redis修改大key报Argument list too long的解决办法:

    线上一个业务出现异常:redis的一个大大大大大key数据有问题,所以导出修改再导入,但遇到了问题: [root@ ~]# /usr/local/redis/bin/redis-cli -h 127. ...

  2. 小白_开始学Scrapy__原理

    整体架构 引擎(Scrapy Engine),用来处理整个系统的数据流处理,触发事务. 调度器(Scheduler),用来接受引擎发过来的请求,压入队列中,并在引擎再次请求的时候返回. 下载器(Dow ...

  3. python实现pow函数(求n次幂,求n次方)

    目录 类型一:求n次幂 类型二:求n开方 类型一:求n次幂 实现 pow(x, n),即计算 x 的 n 次幂函数.其中n为整数.pow函数的实现--leetcode 解法1:暴力法 不是常规意义上的 ...

  4. 做一个函数 返回当前日期、当前时间 格式为“XXXX年XX月XX日”

    import time import datetime def time_strf(now_date):#传入0,1,2返回 当前日期.当前时间.当前日期与时间 today=datetime.date ...

  5. Python 编码encode()、 解码decode()问题

    乱码这种东西,时不时出现.本来开开心心想着我要学习啦,然后兴高采烈打开了比火星文还火星文的字符-- 没事,我可以搞定这堆鬼画符. 先来讲一下为什么有乱码这种东西的存在 故事是这样滴: 字符串是Pyth ...

  6. MySQL进阶5--分组函数 / 分组排序和分组查询 group by(having) /order by

    MySQL进阶--分组排序和分组查询 group by(having) /order by /* 介绍分组函数 功能:用做统计使用,又称为聚合函数或组函数 1.分类: sum, avg 求和 /平均数 ...

  7. 09—mybatis注解配置join查询

    今天来聊mybatis的join查询,怎么说呢,有的时候,join查询确实能提升查询效率,今天举个left join的例子,来看看mybatis的join查询. 就不写的很细了,把主要代码贴出来了. ...

  8. webclient上传下载文件

    定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...

  9. 扫描QPS控制——celery任务分多队列运行

    发包QPS控制,有两个难点. 1. redis交互流量的限制. 假设每分钟有1000条流量任务生成,每条跑20个插件,每个插件发5个数据包,每分钟约发十万请求. 那么在发包处做QPS会遇到一个问题,如 ...

  10. 洛谷P2279 消防局的设立【树形dp】

    题目:https://www.luogu.org/problemnew/show/P2279 题意:一棵树.在节点处建消防站,可以覆盖与他距离在2之内的节点.问最少要建多少个消防站,可以覆盖所有的节点 ...