Here you can find the source of copyFile(File targetFile, File file)
Parameter | Description |
---|---|
targetFile | a parameter |
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File targetFile, File file) throws IOException
//package com.java2s; /**/*from ww w .j a va 2 s.c o m*/ * Copyright 2009, 2011 Welocalize, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Copy file to file * * @param targetFile * @param file * @throws IOException */ public static void copyFile(File targetFile, File file) throws IOException { InputStream is = new FileInputStream(file); FileOutputStream fos = new FileOutputStream(targetFile); byte[] buffer = new byte[1024]; int i = 0; while ((i = is.read(buffer)) != -1) { fos.write(buffer, 0, i); } is.close(); fos.close(); } /** * Copy file(InputStream) to file * * @param targetFile * @param file * @throws IOException */ public static void copyFile(File targetFile, InputStream file) throws IOException { FileOutputStream fos = new FileOutputStream(targetFile); byte[] buffer = new byte[1024]; int i = 0; while ((i = file.read(buffer)) != -1) { fos.write(buffer, 0, i); } file.close(); fos.close(); } }