Here you can find the source of copyFileFromFileSystem(String sourceFileName, File target)
private static void copyFileFromFileSystem(String sourceFileName, File target)
//package com.java2s; /**/*from w w w . j ava 2 s.com*/ * Copyright 2012 msg systems ag * * 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 javax.swing.*; import java.io.*; import java.nio.channels.FileChannel; public class Main { private static void copyFileFromFileSystem(String sourceFileName, File target) { try { File in = new File(sourceFileName); FileChannel inChannel = new FileInputStream(in).getChannel(); FileChannel outChannel = new FileOutputStream(target).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { throw e; } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } } catch (FileNotFoundException e) { JOptionPane.showMessageDialog(null, e); } catch (IOException e) { JOptionPane.showMessageDialog(null, e); } } }