I searched now for a few hours to find a solution to my beginner Java problem but I cannot seem to do it.
I am trying to check a directory for filenames that I would like to test against a list. If the Filename exists I would like to do something. The problem is that the filename is never found, even when the file clearly exists. I am using java.io.File to get the directory filenames.
My problem is that the file is called "test1_1.txt" and the method returns "test1_1.txt" in a println statement but Java tells me they are not the same. Hence I never can actually make Java tell me which files do already exist.
System.out.println(listOfFiles[i].getName());
is showing me "test1_1.txt"
but:
public static void main(String[] args){
File folder = new File(C:\\Users\\M\\Desktop\\coding\\);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++){
if (listOfFiles[i].getName() == "test1_1.txt"){
System.out.println("found");
}
}}
never says "found"
Im grateful for any help.