import java.io.*;class  CopyFile{
public static void main(String args[])throws IOException{
int i;
FileInputStream fin = null; //定义字节文件输入流对象
FileOutputStream fout = null; //定义字节文件输出流对象
if(args.length < 2){
System.out.println("用法: CopyFile 源文件 目标文件");
return;
}
try{
fin = new FileInputStream(args[0]); //创建字节文件输入流
}catch(FileNotFoundException e){
System.out.println("源文件未找到!");
return;
}
try{
fout = new FileOutputStream(args[1]); //创建字节文件输出流
return;
}catch(FileNotFoundException e){
System.out.println("创建目标文件错误");
return;
}
try{
while((i = fin.read()) != -1) //从文件中读入一个字节
fout.write(i); //将字节写入文件中
}catch(FileNotFoundException e){
System.out.println("文件拷贝错误");
}
//关闭流
fin.close();     //无法访问的语句
fout.close();    //无法访问的语句
}   
}

解决方案 »

  1.   

    try{
                fout = new FileOutputStream(args[1]);    //创建字节文件输出流
                return;
            }catch(FileNotFoundException e){
                System.out.println("创建目标文件错误");
                return;
            }这段代码你不管有没有错,都return掉了把try里的return去掉
      

  2.   

    fin.close();     //无法访问的语句
            fout.close();    //无法访问的语句
    关键还是由于return的原因,你都return了,fin.close(); 就不会执行
      

  3.   

    1楼正解
    try{ 
                fout = new FileOutputStream(args[1]);    //创建字节文件输出流 
               //这个 return 是多的.
              //  return; 

            }catch(FileNotFoundException e){ 
                System.out.println("创建目标文件错误"); 
                return; 
            } 
      

  4.   

    在错误里边return,正常里不需要return