Search code examples
javafilemp3move

Why can't I move .mp3-files, but .txts?


So I'm currently trying to move .mp3-files via Java. Afterwards they should be placed in folders for their interpret and album

There I came up with this code:

import java.io.File;

public class Storage {
    String location;

    public Storage(String location){
        this.location = location;
    }

    public void createFolderIfNotExisting(String name){
        File folder = new File(location+name);
        if(!folder.exists()){   
            folder.mkdir();
        }
    }

    public void putInto(String file, String interpret, String album){
        createFolderIfNotExisting(interpret);
        createFolderIfNotExisting(interpret + "//" + album);
        File currentFile = new File(location + file);
        File futureFile = new File(location + interpret + "//" + album + "//" + file);
        currentFile.renameTo(futureFile); 
    }
}

(Location has to be ending on //) (edit) (Location has to be ending on /)

It appears to be creating the folders. But it's not moving the mp3-file. If I try the same with an .txt-file the .txt-file is moved, what appears strange to me.

I also checked if the .mp3-File is correctly recognised. Therefore I used currentFile.exists() . And it is.

So... I am really lost over here. Help would be kindly appreciated. :)


Solution

  • Thanks to Kayman, who helped me figure out that there was a Syntax Error.

    The code itself was completely fine. :)