This expression compares the references that "point" to two different string objects. You compare the references ("the pointers") and the the string objects. This gives you false if you compare th references to two distinct string objects even if their value is the same.
files.substring(dot + 1) == "jpg"
Use ths code if you want to compare the contents of the objects instead of the references:
"jpg".equals(files.substring(dot + 1))
I call the method of the "jpg" string object because that is a constant and isn't null for sure and equals() handles well when its parameter is null.