[Solved] I need save some picture,how can I fix that ByteArrayInputStream to FileInputStream?


MultipartFile’s getInputStream() method returns an InputStream. You don’t have to know what kind of InputStream it returns. As you see, it’s not a FileInputStream, and that should not matter.

All you need to do is read from the InputStream returned and write to your file. You read from an InputStream the same way, whatever the concrete type of the InputStream is. That’s what polymorphism is all about.

So, just remove that useless cast, and use InputSTream instead of FileInputStream.

Note that you can copy all the content of an InputStream to a file in one line of code using Files.

solved I need save some picture,how can I fix that ByteArrayInputStream to FileInputStream?