MultipartFile 获取上传TXT文件字数
@ResponseBody @RequestMapping(value = "/addImgForDynamic")//(发布动态) public Map addImgForDynamic(MultipartFile uploadFile) { Map<String,Object> result = new HashMap(); try { String oo =convertStreamToString(uploadFile); System.out.println("" + oo); System.out.println("" + oo.length()); } catch (Exception e) { e.printStackTrace(); } return result; } public String convertStreamToString(MultipartFile file){ StringBuilder sb; try (InputStream inputStream = file.getInputStream()) { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "/n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return sb.toString(); }
程序员的眼里,不止有代码和bug,还有诗与远方和妹子!!!