package com.github.sparkcaller;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Properties;

public class Utils {
    /*
    Get all the files in the folder 'pathToFolder' ending with 'fileExtension', and return them as an ArrayList.
    */
    public static ArrayList<File> getFilesInFolder(String pathToFolder, String fileExtension) {
        File folder = new File(pathToFolder);
        File[] listOfFiles = folder.listFiles();

        if (listOfFiles != null) {
            ArrayList<File> bamFiles = new ArrayList<File>();

            for (File file : listOfFiles) {
                if (file.isFile() && file.getName().endsWith(fileExtension)) {
                    bamFiles.add(file);
                }
            }
            return bamFiles;
        }

        System.err.println(String.format("The folder: %s is either empty or was not found!", folder.getName()));
        return null;
    }

    public static String removeExtenstion(String filepath, String ext) {
        return filepath.substring(0, filepath.length() - (ext.length()+1));
    }

    public static Properties loadConfigFile(String configFilepath) {
        Properties prop = new Properties();
        InputStream input = null;

        try {
            input = new FileInputStream(configFilepath);
            prop.load(input);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return prop;
    }

    public static File moveToDir(File fileToCopy, String targetPath) {
        File outputFile = new File(targetPath, fileToCopy.getName());
        fileToCopy.renameTo(outputFile);

        return outputFile;
    }

    public static ArrayList<String> possibleStringToArgs(String maybeString) {
        if (maybeString == null) {
            return null;
        }

        String[] args = maybeString.split("\\s+");
        return new ArrayList<>(Arrays.asList(args));
    }
}

@@ -26,16 +26,133 @@
 aller;%0A%0A
+import org.apache.commons.io.FileUtils;%0Aimport org.apache.hadoop.conf.Configuration;%0Aimport org.apache.hadoop.fs.*;%0A%0A
 import j
@@ -1860,24 +1860,43 @@
  targetPath)
+ throws IOException
  %7B%0A        F
@@ -1968,28 +1968,39 @@
     
-fileToCopy.renameTo(
+FileUtils.moveFile(fileToCopy, 
 outp

Use an Apache util when moving files, as this handles error better.