日期:2014-05-20  浏览次数:20727 次

大神帮我看看这段代码有什么问题吧
import java.io.*;
 public class InputOut{
  public static void main(String args[]){
  int a =0;
  FileInputStream in = null;
  FileInputStream out = null;
  in = new FileInputStream("F:/hljk/HelloWorld.java");
  out = new FileOutputStream("D:/java/HW.java");
  try {
  while((a = in.read())!=-1){
  out.write(a);
  }
  in.close();
  out.close();
  }
  catch(FileNotFoundException e1){
  System.out.println("此文件不存在");System.exit(-1);
  }
  catch(IOException e2){
  System.out.println("复制失败");System.exit(-1);
  }
  System.out.println("复制成功");
  }
  }
 

------解决方案--------------------
Java code
public static void main(String[] args) {
        int a = 0;
        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream("F:/hljk/HelloWorld.java");
            out = new FileOutputStream("D:/java/HW.java");
            while ((a = in.read()) != -1) {
                out.write(a);
            }
        } catch (FileNotFoundException e1) {
            System.out.println("此文件不存在");
            System.exit(-1);
        } catch (IOException e2) {
            System.out.println("复制失败");
            System.exit(-1);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        System.out.println("复制成功");

    }

------解决方案--------------------
多看看别人写的代码,多领会一下,然后自己写代码的时候注意一下,就能解决好多问题
------解决方案--------------------
探讨
Java code
public static void main(String[] args) {
int a = 0;
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("……