Search code examples
javafilefileutils

Error: ';' expected comes when executing the programm


I have a small class that should allow me to rename and move some files and directories. Compilation gives me no syntax errors but when trying to execute, it freezes and I an error is displayed : Error: ';' expected - without specifying a line.

My code is:

class Move{ 
public void Move(){}
public static void moveDir(String Name){
    try{
        File Template_1 = new File("Template_1.pdf");
        File NamePDF = new File(Name+"PDF.pdf");
        File NameFile = new File(Name);
        org.apache.commons.io.FileUtils.forceMkdir(NamePDF);
        File usr = new File(org.apache.commons.io.FileUtils.getUserDirectoryPath()+File.separator+"Pdf_Auswertung");
        org.apache.commons.io.FileUtils.waitFor(Template_1,3);
        org.apache.commons.io.FileUtils.copyFile(Template_1, NamePDF);
        org.apache.commons.io.FileUtils.moveFileToDirectory(NamePDF, NameFile, true); 
        org.apache.commons.io.FileUtils.forceDelete(Template_1);
        org.apache.commons.io.FileUtils.moveDirectoryToDirectory(NameFile, usr, true);
    } catch (IOException e){}
}
}

And also I coudn't figure out where a semicolon is missing or a line should be ending. Any ideas?


Solution

  • On this line:

    org.apache.commons.io.FileUtils.forceMkdir(NamePDF);
    

    You are trying to create a directory using a pdf filename. You should specify where are you creating the directory.

    If the NamePDF File exists you could do this to get the parent directory:

    NamePDF.getParentFile();