Here you can find the source of copyFile(BufferedReader in, BufferedWriter out)
private static void copyFile(BufferedReader in, BufferedWriter out) throws IOException
//package com.java2s; /*/*w w w . jav a2 s .co m*/ * Copyright (c) 2008 Pyxis Technologies inc. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, * or see the FSF site: http://www.fsf.org. * * IMPORTANT NOTE : * Kindly contributed by Bertrand Paquet from Octo Technology (http://www.octo.com) */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { private static void copyFile(BufferedReader in, BufferedWriter out) throws IOException { while (true) { String line = in.readLine(); if (line == null) { break; } out.write(line); out.newLine(); out.flush(); } } /** * <p>copyFile.</p> * * @param is a {@link java.io.InputStream} object. * @param deleteOnExit a boolean. * @return a {@link java.io.File} object. * @throws java.io.IOException if any. */ public static File copyFile(InputStream is, boolean deleteOnExit) throws IOException { File f = File.createTempFile("php", ".php"); if (deleteOnExit) { f.deleteOnExit(); } FileWriter fw = new FileWriter(f); copyFile(new BufferedReader(new InputStreamReader(is)), new BufferedWriter(fw)); is.close(); fw.close(); return f; } }