AlexVestin
AlexVestin

Reputation: 2586

How do I save a new path on File

I am making a simple MP3 player and have imported mp3 files from a certain directory. I want to change the path to have double backslashes, however it's not registering.

matchingFiles = dir.listFiles(textFilter);
    for(int i = 0; i<matchingFiles.length; i++){
        String s = matchingFiles[i].toString();
        String t = s.replace("\\", "\\\\");

        matchingFiles[i] = new File(t);
        System.out.println(matchingFiles[i]);
        fileList.add(matchingFiles[i]);
    }

The print gives single backslashes, while t has double. File.renameTo() didn't seem to work either, so I'm wondering how to change the path in an existing File.

Upvotes: 1

Views: 81

Answers (1)

St&#233;phane Bruckert
St&#233;phane Bruckert

Reputation: 22873

The File class aims at representing system paths in its own way, well, the system way. In other words, File understands paths as folders seperated by \, not \\. You can't change that. The question is, why would you?

Upvotes: 2

Related Questions