Here you can find the source of copyFileToFolder(final String resultFile, final String targetPath)
Parameter | Description |
---|---|
resultFile | Existing results file |
targetPath | Where to save xml file |
public static boolean copyFileToFolder(final String resultFile, final String targetPath)
//package com.java2s; /*//from w ww . jav a 2 s . c om * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: Definitions for the class Util * */ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; public class Main { /** * Copies stored memory leak analysis file to given folder. * * @param resultFile * Existing results file * @param targetPath * Where to save xml file * @return True if copy success otherwise False */ public static boolean copyFileToFolder(final String resultFile, final String targetPath) { FileChannel inputChannel = null; FileChannel ouputChannel = null; FileInputStream inStream = null; FileOutputStream outStream = null; boolean returnValue = true; try { // get channel to existing file inStream = new FileInputStream(resultFile); inputChannel = inStream.getChannel(); // get channel to new file outStream = new FileOutputStream(targetPath, false); ouputChannel = outStream.getChannel(); // get existing file size final long size = inputChannel.size(); // position inside the file long position = 0; // copy file contents if there are data to copy while (position < size) { position += ouputChannel.transferFrom(inputChannel, position, size - position); } // close opened channels inputChannel.close(); inStream.close(); ouputChannel.close(); outStream.close(); } catch (FileNotFoundException fnfe) { returnValue = false; } catch (IOException ioe) { returnValue = false; } finally { try { if (inputChannel != null) { inputChannel.close(); inputChannel = null; } } catch (IOException ioe) { returnValue = false; } try { if (inStream != null) { inStream.close(); inStream = null; } } catch (IOException ioe) { returnValue = false; } try { if (ouputChannel != null) { ouputChannel.close(); ouputChannel = null; } } catch (IOException ioe) { returnValue = false; } try { if (outStream != null) { outStream.close(); outStream = null; } } catch (IOException ioe) { returnValue = false; } } return returnValue; } }