Search code examples
javafileutils

FileUtils.copyFile() crashes the program when trying to copy an exe


I have been trying a lot of different options for copying files in Java and none have been working. The one that I was using when I think I found the real issue was FileUtils. Here is the code

        public void createUSBButtonAction() throws IOException {

                for(Object obj: programList.getItems()){

                    File src = new File("C:\\Users\\JohnsonL\\Desktop\\flashTranserProj\\flashTransferProj\\src\\sample\\Installers\\" + obj.toString());
                    File dst = new File("D:/Test/" + obj.toString());
                    System.out.println(dst.getUsableSpace());
                    FileUtils.copyFile(src, dst);
            }

It works fine until I copy an exe file. When I do that the program stops responding and a prompt comes up saying the JDK stopped working and doesn't give me any errors.

If I have to switch to another form of copying files I will but I would like to stick with FileUtils


Solution

  • The file copy was taking too long so it was stopping the rest of the program to copy the file over. I fixed this by copying the file on another thread.