code: public static void saveTo(String path, InputStream in) throws IOException {
          if (in == null)
              throw new IllegalArgumentException("input stream cannot be null");
          if (path == null)
              throw new IllegalArgumentException("path cannot be null");
  
          try (OutputStream out = new BufferedOutputStream(
                                          Files.newOutputStream(
                                                  Paths.get(path), 
                                                  StandardOpenOption.CREATE, 
                                                  StandardOpenOption.APPEND))) {
              byte[] bytes = new byte[1024];
              for (int x = in.read(bytes); x != -1; x = in.read(bytes))
                  out.write(bytes, 0, x);
          }
      }
docs: Saves content read from input stream into a file.
  
  @param path path to file.
  @param in  input stream to read content from.
  @throws IOException IO error
  @throws IllegalArgumentException if stream is null or path is null