Here you can find the source of copyFile(File fromFile, File toFile, IProgressMonitor monitor)
Parameter | Description |
---|---|
fromFile | the file to copy |
toFile | the file to be copied to |
monitor | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void copyFile(File fromFile, File toFile, IProgressMonitor monitor) throws IOException
//package com.java2s; /*//from w w w .j a v a 2s. co m * Copyright (c) 2014, the Dart project authors. * * Licensed under the Eclipse Public License v1.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.eclipse.org/legal/epl-v10.html * * 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 org.eclipse.core.runtime.IProgressMonitor; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copies a file, given the file to be copied and copy to * * @param fromFile the file to copy * @param toFile the file to be copied to * @param monitor * @throws IOException */ public static void copyFile(File fromFile, File toFile, IProgressMonitor monitor) throws IOException { byte[] data = new byte[4096]; InputStream in = new FileInputStream(fromFile); toFile.delete(); OutputStream out = new FileOutputStream(toFile); monitor.beginTask("Copy " + fromFile.toString(), (int) fromFile.length()); int count = in.read(data); while (count != -1) { out.write(data, 0, count); monitor.worked(count); count = in.read(data); } in.close(); out.close(); toFile.setLastModified(fromFile.lastModified()); monitor.done(); } }