1. Download the file and save the file locally. (Try excel only);
2. Check the title of the document;
3. Get the imported batch (take a value of a table and add 1);
4. Loop to get the value of a certain row and a certain column of the file and set it into the object;
5. The legality of the test value;
6. Loop to save to the object.
7. Use map to transfer the wrong information and correct information, JSONObject.fromObject(map);
public String uploadFile() throws Exception {logger.info("Start import rule file: " + fileInputFileName);InputStream is = new FileInputStream(fileInput);String uploadPath = ServletActionContext.getServletContext().getRealPath("/upload");System.out.println(uploadPath);File targetFile = new File(uploadPath, this.getFileInputFileName());OutputStream os = new FileOutputStream(targetFile);byte[] buffer = new byte[1024];int length = 0;while ((length = is.read(buffer)) > 0) {os.write(buffer, 0, length);}is.close();os.close();Map<String, Object> map = personalKPIMonitorManualRuleService.importRules(targetFile);HttpServletResponse response = ServletActionContext.getResponse();response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();out.println(JSONObject.fromObject(map));// if(flag==true){// logger.info("Rules file import successfully: "+fileInputFileName);// out.println("Rules file import successfully: "+fileInputFileName);// }else{// logger.info("Rule file import failed: "+fileInputFileName);// out.println("Rule file import failed, see the log for details: "+fileInputFileName);// }out.flush();out.close();return null;}The above example of uploading java files to reading file content is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.