0

I wrote a class Storage, which should represent a Windows directory, by using the file class. It should have some Methods as the folderOnly() method, which returns a boolean, if there are just folder in my Storage. Extra information: There are just .mp3-files and other folder in the directory I am looking at.

So here the code:

import java.io.File;

public class Storage {
    String location;

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

    public boolean folderOnly(){
        boolean onlyFolder = true;
        File folder = new File(location);
        String [] folderArray = folder.list();
        for(int i = 0; i < folderArray.length && onlyFolder ; i++){
            if(folderArray[i].length() >= 4 && folderArray[i].substring(folderArray[i].length()-4) == ".mp3"){
                onlyFolder = false;
            }
        }
        return onlyFolder;
    }
}

So if I create a "Storage" object for a directoy with a lot of .mp3-files (even if the number doesn't matter) it still returns true. So I checked for intermediate results:

The String, that is created by the line folderArray[i].substring(folderArray[i].length()-4) , outprinted by System.out.println(String s) seems to be ".mp3". But if I compare it to ".mp3" , false is returned.

What am I missing out on?

Please don't blame me if there's a really simple solution, or my English is really hard to understand. I'm new to whole thing of English and programming. :)

oRookie
  • 265
  • 2
  • 4
  • 13

0 Answers0