public static void writeToFile ( InputStream uploadedInputStream , String uploadedFileLocation ) throws IOException { File file = new File ( uploadedFileLocation ) ; file . getParentFile ( ) . mkdirs ( ) ; int read = 0 ; byte [ ] bytes = new byte [ 1024 ] ; try ( OutputStream out = new FileOutputStream ( file ) ) { while ( ( read = uploadedInputStream . read ( bytes ) ) != - 1 ) { out . write ( bytes , 0 , read ) ; } out . flush ( ) ; } }
save uploaded file to new location