methods inside catches

Hi. I'm having a problem with this program that copies files...it's suppose to continuously prompt the user for a file to copy, and the name of the destination file for it to be copied to, until the user types QUIT. This is a lab for my cs class where we have to make custom exceptions that catch all sorts of exceptional situations that could happen with this program...one of the things being, if the destination file already exists, we have to ask the user if they really want to overwrite it...here's my code for it so far (the main while loop at least)

while (!infile.equals("QUIT")){

outfile = getFilename("Enter destination file: ");

File input =new File(infile);

File output =new File(outfile);

try{

if (input.equals(output)){

thrownew FilesAreSameException();

}

if (output.exists()){

thrownew OverwriteFileException();

}

copyFile(infile, outfile);

}catch (FilesAreSameException e){

System.out.println("Source file and destination file cannot be the same");

}catch (OverwriteFileException e){

Scanner scan =new Scanner(System.in);

String answer;

System.out.print("Warning: file already exists! " +

"Do you to overwrite it? (Y/N) ");

answer = scan.nextLine();

if ((answer =="Y") || (answer =="y")){

copyFile(infile, outfile);

}

}

infile = getFilename("Enter source file: ");

}

I can't find anything wrong with it, and as far as the prompting and the looping goes, it works like it should. But the thing is, if the destination file exists, and the user types y or Y it simply doesn't copy the file. I know the copfyFile method works because it works if you try to copy a file normally. The only thing I can think of is maybe calling methods doesn't work like it normally would inside a catch or something....any ideas?

[2941 byte] By [Genji102a] at [2007-11-26 21:49:06]
# 1

<snip>

>

> I can't find anything wrong with it, and as far as

> the prompting and the looping goes, it works like it

> should. But the thing is, if the destination file

> exists, and the user types y or Y it simply doesn't

> copy the file. I know the copfyFile method works

> because it works if you try to copy a file normally.

> The only thing I can think of is maybe calling

> methods doesn't work like it normally would inside a

> catch or something....any ideas?

See section 15.21.3 of the Java Language Specification:

http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.21.3

Jim S.

Niceguy1a at 2007-7-10 3:40:21 > top of Java-index,Java Essentials,Java Programming...
# 2
Oh yeah...wow that was really really really stupid of me *facepalm* I forgot you're suppose to use .equals .. I even used it inside the while....*facepalms again*
Genji102a at 2007-7-10 3:40:21 > top of Java-index,Java Essentials,Java Programming...