从HttpServletRequest中获取前端传过来的文件

@RequestMapping("/uploadFile")
    public void fileUpload(HttpServletRequest request) throws IllegalStateException, IOException {

        MultipartHttpServletRequest multipartRequest =
                WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
        MultipartFile file = multipartRequest.getFile("file");
        System.out.println(file);

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.getInputStream()));
        String lineTxt;
        while ((lineTxt=bufferedReader.readLine())!=null){
            System.out.println(lineTxt);
        }

你可能感兴趣的:(Java,前端,java,java-ee)