Here you can find the source of saveFile(InputStream st, File testFile)
public static File saveFile(InputStream st, File testFile) throws FileNotFoundException, IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Patrick Hofer//from w ww . j ava 2 s .c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Patrick Hofer - initial API and implementation *******************************************************************************/ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; public class Main { public static File saveFile(InputStream st, File testFile) throws FileNotFoundException, IOException { BufferedReader r = new BufferedReader(new InputStreamReader(st)); String line; try (PrintStream wr = new PrintStream(testFile)) { while ((line = r.readLine()) != null) { wr.println(line); } } return testFile; } }