File filename= new File("Output " + n + ".txt");
while (filename.exists()) {
...
filename= new File("Output " + n + ".txt");
}
File filename= new File("Output " + n + ".txt");
while (filename.exists()) {
...
filename= new File("Output " + n + ".txt");
}