Error With BufferedOutputStream java :The constructor BufferedOutputStream(FileOutputStream) is undefined

Amine El Mandour :

hello everyone please i get some erorr so i try to import excel file with spring boot et React js but in my backend i got error

The constructor BufferedOutputStream(FileOutputStream) is undefined

the method is :

@RequestMapping(value="/upload", method=RequestMethod.POST)
    public @ResponseBody ResponseEntity<String>  handleFileUpload(@RequestParam("name") String name,
            @RequestParam("file") MultipartFile file) throws Exception{
        if (name.contains("/")) {
            return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("Folder separators not allowed.");
        } else if (name.contains("/")) {
            return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("Relative pathnames not allowed.");
        } else if (!name.endsWith(".jar")) {
            return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("File type not allowed.  Must be a Jar file type ending in '.jar'.");
        }

        if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();
                BufferedOutputStream stream =  new BufferedOutputStream(new FileOutputStream(new File(name)));
                stream.write(bytes);
                stream.close();
                return ResponseEntity.ok("File " + name + " uploaded.");
            } catch (Exception e) {
                return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(e.getMessage());
            }
        } else {
            return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body("You failed to upload " + name + " because the file was empty.");
        }
    }
}

i get error in this line :

        BufferedOutputStream stream =  new BufferedOutputStream(new FileOutputStream(new File(name)));
Rahul Nagekar :

The only reason I can think of is, you have imported a different class than following

import java.io.BufferedOutputStream;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=403906&siteId=1