String are compared using equals()
not !=
or ==
.
So you need
if (!fileName .equals(failstring)) {
fileName = fileName + ".txt";
} else {
System.exit(1);
}
See the Java tutorial for more details: http://docs.oracle.com/javase/tutorial/java/data/comparestrings.html
Btw: it's usually better to use "positive" expressions rather than negated ones (the human brain copes better with them). So it is recommended to use:
if (fileName .equals(failstring)) {
System.exit(1);
} else {
fileName = fileName + ".txt";
}
instead