Example usage for org.apache.commons.io FileUtils copyFileToDirectory

List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyFileToDirectory.

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:com.hp.test.framework.Reporting.TestPath.java

public static void main(String ar[]) throws IOException {
    URL location = Test.class.getProtectionDomain().getCodeSource().getLocation();

    String path = location.toString();
    path = path.substring(6, path.indexOf("lib"));
    String Logos_path = path + "ATU Reports/HTML_Design_Files/IMG";
    String Source_logs_path = path + "HTML_Design_Files/IMG";
    String Source_Framework_Logo_path = Source_logs_path + "/Framework_Logo.jpg";
    String Source_hp_logo_path = Source_logs_path + "/hp.png";
    String Source_reports_path = Source_logs_path + "/reports.jpg";
    File Target_dir = new File(Logos_path);
    File Source = new File(Source_Framework_Logo_path);
    FileUtils.copyFileToDirectory(Source, Target_dir);
    File Source_Reports = new File(Source_reports_path);
    FileUtils.copyFileToDirectory(Source_Reports, Target_dir);
    File Source_hp = new File(Source_hp_logo_path);
    FileUtils.copyFileToDirectory(Source_hp, Target_dir);

}

From source file:com.discursive.jccook.io.FileCopyExample.java

public static void main(String[] args) {
    try {//from w w w .j a  v a2 s  . c  o m
        File src = new File("test.dat");
        File dest = new File("test.dat.bak");

        FileUtils.copyFile(src, dest);
    } catch (IOException ioe) {
        System.out.println("Problem copying file.");
    }

    try {
        File src = new File("test.dat");
        File dir = new File("./temp");

        FileUtils.copyFileToDirectory(src, dir);
    } catch (IOException ioe) {
        System.out.println("Problem copying file to dir.");
    }

    try {
        String string = "Blah blah blah";
        File dest = new File("test.tmp");

        FileUtils.writeStringToFile(dest, string, "ISO-8859-1");
    } catch (IOException ioe) {
        System.out.println("Error writing out a String.");
    }
}

From source file:com.siva.filewritterprogram.Mp3FileWritterTool.java

public static void main(String[] args) {
    File directory = new File("D:\\Siva\\Entertainment\\EvergreenHits");

    FileFilter filter = new FileFilter() {
        @Override//  www .ja v a2 s  .  com
        public boolean accept(File file) {
            if (file.getName().endsWith(".mp3")) {
                return true;
            } else {
                return false;
            }
        }
    };
    File[] subdirs = directory.listFiles();
    for (File subDir : subdirs) {
        try {
            System.out.println("Going to read files under : " + subDir);
            if (subDir.isDirectory()) {
                File[] files = subDir.listFiles(filter);
                if (files != null) {
                    for (File file : files) {
                        FileUtils.copyFileToDirectory(file, new File(directory.getPath() + "\\toTransfer"));
                    }
                } else {
                    System.out.println("There are no songs inside. [" + subDir.getName() + "]");
                }
            } else {
                System.out.println("Not a directory. [" + subDir.getName() + "]");
            }
        } catch (IOException ex) {
            Logger.getLogger(Mp3FileWritterTool.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:gda.util.PackageMaker.java

/**
 * @param args/*from  w w w.ja  va2 s.  com*/
 */
public static void main(String args[]) {
    String destDir = null;
    if (args.length == 0)
        return;
    String filename = args[0];
    if (args.length > 1)
        destDir = args[1];
    try {
        ClassParser cp = new ClassParser(filename);
        JavaClass classfile = cp.parse();
        String packageName = classfile.getPackageName();
        String apackageName = packageName.replace(".", File.separator);
        if (destDir != null)
            destDir = destDir + File.separator + apackageName;
        else
            destDir = apackageName;
        File destFile = new File(destDir);
        File existFile = new File(filename);
        File parentDir = new File(existFile.getAbsolutePath().substring(0,
                existFile.getAbsolutePath().lastIndexOf(File.separator)));
        String allFiles[] = parentDir.list();
        Vector<String> selectedFiles = new Vector<String>();
        String toMatch = existFile.getName().substring(0, existFile.getName().lastIndexOf("."));
        for (int i = 0; i < allFiles.length; i++) {
            if (allFiles[i].startsWith(toMatch + "$"))
                selectedFiles.add(allFiles[i]);
        }
        FileUtils.copyFileToDirectory(existFile, destFile);
        Object[] filestoCopy = selectedFiles.toArray();
        for (int i = 0; i < filestoCopy.length; i++) {
            FileUtils.copyFileToDirectory(new File((String) filestoCopy[i]), destFile);
        }
    }

    catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.cyphercove.dayinspace.desktop.AtlasGenerator.java

public static void main(String[] args) throws Exception {

    //Delete old pack
    File oldPackFile = new File(TARGET_DIR + "/" + Assets.MAIN_ATLAS + Assets.ATLAS_EXTENSION);
    if (oldPackFile.exists()) {
        System.out.println("Deleting old pack file");
        oldPackFile.delete();/*from   w  w  w.  j  a va  2s. c  om*/
    }

    //Delete old font files
    Collection<File> oldFontFiles = FileUtils.listFiles(new File(TARGET_DIR), new RegexFileFilter(".*\\.fnt"),
            TrueFileFilter.INSTANCE);
    for (File file : oldFontFiles) {
        System.out.println("Copying font file: " + file.getName());
        FileUtils.deleteQuietly(file);
    }

    //Create PNGs for GIF frames
    GifProcessor gifProcessor = new GifProcessor(0.015f);
    ArrayList<FileProcessor.Entry> gifFrames = gifProcessor.process(SOURCE_DIR, SOURCE_DIR);

    //Pack them
    TexturePacker.Settings settings = new TexturePacker.Settings();
    settings.atlasExtension = Assets.ATLAS_EXTENSION;
    TexturePacker.process(settings, SOURCE_DIR, TARGET_DIR, Assets.MAIN_ATLAS);

    //Copy over any fonts
    Collection<File> fontFiles = FileUtils.listFiles(new File(SOURCE_DIR), new RegexFileFilter(".*\\.fnt"),
            TrueFileFilter.INSTANCE);
    File destDir = new File(TARGET_DIR);
    for (File file : fontFiles) {
        System.out.println("Copying font file: " + file.getName());
        FileUtils.copyFileToDirectory(file, destDir);
    }

    //Delete the GIF frames that were generated.
    for (File file : gifProcessor.getGeneratedFiles())
        file.delete();
}

From source file:com.hp.test.framework.jmeterTests.GetJmeterTestCaseFileList.java

public static void main(String ar[]) throws IOException {
    ReadJmeterConfigProps readjmeterconfigprops = new ReadJmeterConfigProps();
    String path = readjmeterconfigprops.getProperty("location.java.files");
    path = path + "/";
    // getjmeterTestcaseList();
    String basepath = replacelogs();
    String webdriver_path = basepath + "/libs/selenium-server-standalone-2.45.0.jar";
    try {//  ww w .  ja  v a2  s  . co m
        String Command = "javac -d " + path + "classes " + "-cp \"" + webdriver_path + "\" " + path + "*.java";
        if (runProcess(Command) != 0) {
            System.out.println("Error in compiling jmeter testcases");
            return;
        }
        System.out.println("Compiling the Sources succes");
        //  String temp_jar="jar cf  " + path + "JunitTests.jar " + path + "*.class .";
        //  System.out.println("**"+temp_jar);
        if (runProcess("jar cf  " + path + "JunitTests.jar -C " + path + "classes/ .") != 0) {
            System.out.println("Error in creating jar for jmeter testcases");
            return;
        }

        System.out.println("Creation of Jar file success");

        FileUtils.copyFileToDirectory(new File(path + "JunitTests.jar"),
                new File(basepath + "jmeter/apache-jmeter-2.13/lib/junit/"));
        System.out.println("Copy jar file to libs folder succcess");

        CreateJmxFilesforUI createjmxfilesforui = new CreateJmxFilesforUI();
        createjmxfilesforui.createJmxFilesforui();
        System.out.println("Jmeter Testplans Creation is success");
    } catch (Exception e) {
        System.out.println("Exception in making jars");
    }
}

From source file:de.codecentric.elasticsearch.plugin.kerberosrealm.support.EmbeddedKRBServer.java

public static void main(final String[] args) throws Exception {
    final File workDir = new File(".");
    final EmbeddedKRBServer eks = new EmbeddedKRBServer();
    eks.realm = "DUMMY.COM";
    eks.start(workDir);//w w  w  .j ava2s  .  c o m
    eks.getSimpleKdcServer().createPrincipal("kirk/admin@DUMMY.COM", "kirkpwd");
    eks.getSimpleKdcServer().createPrincipal("uhura@DUMMY.COM", "uhurapwd");
    eks.getSimpleKdcServer().createPrincipal("service/1@DUMMY.COM", "service1pwd");
    eks.getSimpleKdcServer().createPrincipal("service/2@DUMMY.COM", "service2pwd");
    eks.getSimpleKdcServer().exportPrincipal("service/1@DUMMY.COM", new File(workDir, "service1.keytab")); //server, acceptor
    eks.getSimpleKdcServer().exportPrincipal("service/2@DUMMY.COM", new File(workDir, "service2.keytab")); //server, acceptor

    eks.getSimpleKdcServer().createPrincipal("HTTP/localhost@DUMMY.COM", "httplocpwd");
    eks.getSimpleKdcServer().exportPrincipal("HTTP/localhost@DUMMY.COM", new File(workDir, "httploc.keytab")); //server, acceptor

    eks.getSimpleKdcServer().createPrincipal("HTTP/localhost@DUMMY.COM", "httpcpwd");
    eks.getSimpleKdcServer().exportPrincipal("HTTP/localhost@DUMMY.COM", new File(workDir, "http.keytab")); //server, acceptor

    final TgtTicket tgt = eks.getSimpleKdcServer().getKrbClient().requestTgtWithPassword("kirk/admin@DUMMY.COM",
            "kirkpwd");
    eks.getSimpleKdcServer().getKrbClient().storeTicket(tgt, new File(workDir, "kirk.cc"));

    try {
        try {
            FileUtils.copyFile(new File("/etc/krb5.conf"), new File("/etc/krb5.conf.bak"));
        } catch (final Exception e) {
            //ignore
        }
        FileUtils.copyFileToDirectory(new File(workDir, "krb5.conf"), new File("/etc/"));
        System.out.println("Generated krb5.conf copied to /etc");
    } catch (final Exception e) {
        System.out.println("Unable to copy generated krb5.conf to /etc die to " + e.getMessage());
    }
}

From source file:grnet.validation.XMLValidation.java

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method ssstub

    Enviroment enviroment = new Enviroment(args[0]);

    if (enviroment.envCreation) {
        String schemaUrl = enviroment.getArguments().getSchemaURL();
        Core core = new Core(schemaUrl);

        XMLSource source = new XMLSource(args[0]);

        File sourceFile = source.getSource();

        if (sourceFile.exists()) {

            Collection<File> xmls = source.getXMLs();

            System.out.println("Validating repository:" + sourceFile.getName());

            System.out.println("Number of files to validate:" + xmls.size());

            Iterator<File> iterator = xmls.iterator();

            System.out.println("Validating against schema:" + schemaUrl + "...");

            ValidationReport report = null;
            if (enviroment.getArguments().createReport().equalsIgnoreCase("true")) {

                report = new ValidationReport(enviroment.getArguments().getDestFolderLocation(),
                        enviroment.getDataProviderValid().getName());

            }//www . j  ava2s .  c  o  m

            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(enviroment.getArguments().getQueueHost());
            factory.setUsername(enviroment.getArguments().getQueueUserName());
            factory.setPassword(enviroment.getArguments().getQueuePassword());

            while (iterator.hasNext()) {

                StringBuffer logString = new StringBuffer();
                logString.append(sourceFile.getName());
                logString.append(" " + schemaUrl);

                File xmlFile = iterator.next();
                String name = xmlFile.getName();
                name = name.substring(0, name.indexOf(".xml"));

                logString.append(" " + name);

                boolean xmlIsValid = core.validateXMLSchema(xmlFile);

                if (xmlIsValid) {
                    logString.append(" " + "Valid");
                    slf4jLogger.info(logString.toString());

                    Connection connection = factory.newConnection();
                    Channel channel = connection.createChannel();
                    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

                    channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes());
                    channel.close();
                    connection.close();
                    try {
                        if (report != null) {

                            report.raiseValidFilesNum();
                        }

                        FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderValid());
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    logString.append(" " + "Invalid");
                    slf4jLogger.info(logString.toString());

                    Connection connection = factory.newConnection();
                    Channel channel = connection.createChannel();
                    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

                    channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes());
                    channel.close();
                    connection.close();

                    try {
                        if (report != null) {

                            if (enviroment.getArguments().extendedReport().equalsIgnoreCase("true"))
                                report.appendXMLFileNameNStatus(xmlFile.getPath(), Constants.invalidData,
                                        core.getReason());

                            report.raiseInvalidFilesNum();
                        }
                        FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderInValid());
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

            if (report != null) {
                report.writeErrorBank(core.getErrorBank());
                report.appendGeneralInfo();
            }
            System.out.println("Validation is done.");

        }

    }
}

From source file:grnet.filter.XMLFiltering.java

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method ssstub

    Enviroment enviroment = new Enviroment(args[0]);

    if (enviroment.envCreation) {
        Core core = new Core();

        XMLSource source = new XMLSource(args[0]);

        File sourceFile = source.getSource();

        if (sourceFile.exists()) {

            Collection<File> xmls = source.getXMLs();

            System.out.println("Filtering repository:" + enviroment.dataProviderFilteredIn.getName());

            System.out.println("Number of files to filter:" + xmls.size());

            Iterator<File> iterator = xmls.iterator();

            FilteringReport report = null;
            if (enviroment.getArguments().getProps().getProperty(Constants.createReport)
                    .equalsIgnoreCase("true")) {
                report = new FilteringReport(enviroment.getArguments().getDestFolderLocation(),
                        enviroment.getDataProviderFilteredIn().getName());
            }//from  w  ww . ja  va  2s. c om

            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost(enviroment.getArguments().getQueueHost());
            factory.setUsername(enviroment.getArguments().getQueueUserName());
            factory.setPassword(enviroment.getArguments().getQueuePassword());

            while (iterator.hasNext()) {

                StringBuffer logString = new StringBuffer();
                logString.append(enviroment.dataProviderFilteredIn.getName());
                File xmlFile = iterator.next();

                String name = xmlFile.getName();
                name = name.substring(0, name.indexOf(".xml"));
                logString.append(" " + name);

                boolean xmlIsFilteredIn = core.filterXML(xmlFile, enviroment.getArguments().getQueries());

                if (xmlIsFilteredIn) {
                    logString.append(" " + "FilteredIn");
                    slf4jLogger.info(logString.toString());

                    Connection connection = factory.newConnection();
                    Channel channel = connection.createChannel();
                    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

                    channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes());
                    channel.close();
                    connection.close();

                    try {
                        if (report != null) {
                            report.appendXMLFileNameNStatus(xmlFile.getPath(), Constants.filteredInData);
                            report.raiseFilteredInFilesNum();
                        }

                        FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderFilteredIn());
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        // e.printStackTrace();
                        e.printStackTrace();
                        System.out.println("Filtering failed.");
                    }
                } else {
                    logString.append(" " + "FilteredOut");
                    slf4jLogger.info(logString.toString());

                    Connection connection = factory.newConnection();
                    Channel channel = connection.createChannel();
                    channel.queueDeclare(QUEUE_NAME, false, false, false, null);

                    channel.basicPublish("", QUEUE_NAME, null, logString.toString().getBytes());
                    channel.close();
                    connection.close();
                    try {
                        if (report != null) {
                            report.appendXMLFileNameNStatus(xmlFile.getPath(), Constants.filteredOutData);
                            report.raiseFilteredOutFilesNum();
                        }
                        FileUtils.copyFileToDirectory(xmlFile, enviroment.getDataProviderFilteredOuT());
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        // e.printStackTrace();
                        e.printStackTrace();
                        System.out.println("Filtering failed.");
                    }
                }
            }
            if (report != null) {

                report.appendXPathExpression(enviroment.getArguments().getQueries());

                report.appendGeneralInfo();
            }
            System.out.println("Filtering is done.");
        }

    }
}

From source file:mujava.cli.testnew.java

public static void main(String[] args) throws IOException {
    testnewCom jct = new testnewCom();
    String[] argv = { "Flower", "/Users/dmark/mujava/src/Flower" };
    new JCommander(jct, args);

    muJavaHomePath = Util.loadConfig();
    // muJavaHomePath= "/Users/dmark/mujava";

    // check if debug mode
    if (jct.isDebug() || jct.isDebugMode()) {
        Util.debug = true;//from   ww  w . ja v a  2 s  . com
    }
    System.out.println(jct.getParameters().size());
    sessionName = jct.getParameters().get(0); // set first parameter as the
    // session name

    ArrayList<String> srcFiles = new ArrayList<>();

    for (int i = 1; i < jct.getParameters().size(); i++) {
        srcFiles.add(jct.getParameters().get(i)); // retrieve all src file
        // names from parameters
    }

    // get all existing session name
    File folder = new File(muJavaHomePath);
    if (!folder.isDirectory()) {
        Util.Error("ERROR: cannot locate the folder specified in mujava.config");
        return;
    }
    File[] listOfFiles = folder.listFiles();
    // null checking
    // check the specified folder has files or not
    if (listOfFiles == null) {
        Util.Error("ERROR: no files in the muJava home folder " + muJavaHomePath);
        return;
    }
    List<String> fileNameList = new ArrayList<>();
    for (File file : listOfFiles) {
        fileNameList.add(file.getName());
    }

    // check if the session is new or not
    if (fileNameList.contains(sessionName)) {
        Util.Error("Session already exists.");
    } else {
        // create sub-directory for the session
        setupSessionDirectory(sessionName);

        // move src files into session folder
        for (String srcFile : srcFiles) {
            // new (dir, name)
            // check abs path or not

            // need to check if srcFile has .java at the end or not
            if (srcFile.length() > 5) {
                if (srcFile.substring(srcFile.length() - 5).equals(".java")) // name has .java at the end, e.g. cal.java
                {
                    // delete .java, e.g. make it cal
                    srcFile = srcFile.substring(0, srcFile.length() - 5);
                }
            }

            File source = new File(srcFile + ".java");

            if (!source.isAbsolute()) // relative path, attach path, e.g. cal.java, make it c:\mujava\cal.java
            {
                source = new File(muJavaHomePath + "/src" + java.io.File.separator + srcFile + ".java");

            }

            File desc = new File(muJavaHomePath + "/" + sessionName + "/src");
            FileUtils.copyFileToDirectory(source, desc);

            // compile src files
            // String srcName = "t";
            boolean result = compileSrc(srcFile);
            if (result)
                Util.Print("Session is built successfully.");
        }

    }

    // System.exit(0);
}