Here you can find the source of copy(Path sourcePath, Path destinationPath)
Parameter | Description |
---|---|
sourcePath | Path for source |
destinationPath | Path for destination |
Parameter | Description |
---|---|
IOException | an exception |
private static void copy(Path sourcePath, Path destinationPath) throws Exception
//package com.java2s; /*/*from w ww .java 2 s. com*/ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * 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.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; public class Main { /** * Copy files. * * @param sourcePath Path for source * @param destinationPath Path for destination * @throws IOException */ private static void copy(Path sourcePath, Path destinationPath) throws Exception { String basedir = System.getProperty("basedir"); if (basedir == null) { basedir = Paths.get(".").toString(); } sourcePath = Paths.get(basedir).resolve(sourcePath); destinationPath = getCarbonHome().resolve(destinationPath); createOutputFolderStructure(destinationPath); try { Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new Exception("Error occurred while copying '" + sourcePath + "' file to " + destinationPath + ".", e); } } /** * Return carbon home path * * @return Path for carbon home */ private static Path getCarbonHome() { return Paths.get(System.getProperty("carbon.home")); } /** * Create the directory structure. * * @param destinationPath Path to file copying destination * @throws IOException */ private static void createOutputFolderStructure(Path destinationPath) throws Exception { Path parentPath = destinationPath.getParent(); try { Files.createDirectories(parentPath); } catch (IOException e) { throw new Exception( "Error occurred while creating the directory '" + parentPath + "'.", e); } } }