-2

So I am trying to copy one file from one place to the other using the solution found here : Copying files from one directory to another in Java

My code creates the new directory but cant seem to find the file ,even though the landedtitlesFile is pointing to the proper path and file. I always get my "blast" comment in case you were wondering if my program gets to the end of the method.

Thank you for your time and patience.

private File landedtitlesFile = new File("C:\\Program Files (x86)\\Steam\\SteamApps\\common\\Crusader Kings II\\common\\landed_titles\\landed_titles.txt");
private String modPath = "C:\\Users\\Bernard\\Documents\\Paradox Interactive\\Crusader Kings II\\mod\\viking";


public void createCopyLandedTitles(Boolean vanilla){
    if (vanilla == true) {
        File dir = new File(modPath + "\\common\\landed_titles");
        dir.mkdir();
        try{
            FileUtils.copyFile(landedtitlesFile,dir);
        }
        catch (IOException e ){
            System.out.println("blast");
        }
    }
Community
  • 1
  • 1
BURNS
  • 711
  • 1
  • 9
  • 20

1 Answers1

2

copyFile expects the second parameter to be the destination file, not a destination directory. You need to give it the target name of the file within that directory:

FileUtils.copyFile(
    landedtitlesFile,
    new File(dir, landedtitlesFile.getName());

Exception objects generally contain some information on the cause. If you print out the exception with e.printStackTrace(); (or rethrow it up the stack with throw new RuntimeException(e);) then you will be able to see what it says.

Boann
  • 48,794
  • 16
  • 117
  • 146