Start New Discussion within our Software Development Community

Hello all,
I want to ask you what this code mean.

import java.io.*; 
class CopyFile { 
  public static void main(String[] args) throws IOException{
	 int i; 
	 FileReader fin; FileWriter fout; 
	   try { 
		fin = new FileReader(args[0]);
	        fout = new FileWriter(args[1]);
	    }
	    catch (FileNotFoundException e) { 
	        System.out.println("Error opening output file."); 
	        return; //what the meaning of this line?
	    } 
	    catch (IndexOutOfBoundsException e) { 
		System.out.println("Usage: CopyFile from .. to .."); 
		return; //what the meaning of this line?  
	    } 
	    try { 
		do { 
		       i = fin.read(); 
		       if (i!=-1)              
		          fout.write(i); 
		} while (i!= -1); 
	    } 
	    catch (IOException e) { 
		    System.out.println("File error."); 
	    } 
	    finally{
		    try{
			if (fin!=null)  fin.close(); 
			if (fout!=null)  fout.close(); 
		    } 
		    catch(IOException e){
			System.out.println(e.getMessage());
		    }
	    }
	}
}

As I know, return keyword is usually followed by a return value.
Can you explain what is the meaning of that line?

Thanks in advance

The return type for that method is defined as void, ie it does not return a value, so the is no return value to go with the return; statement. The return; just terminates execution of the method (in this case because there has been a fatal error).

This question has already been answered. Start a new discussion instead.