刚开始学习Java,一直想学但总是坚持不下来,回到家就想着玩游戏,看来是要下决心了,2010年要好好学习Java了. 这是在网上看到的两个小例子,自己也做了一遍. 1. try { FileInputStream in=new FileInputStream("C:/1.txt"); FileOutputStream out=new FileOutputStream("C:/2.txt"); byte[] by=new byte[1024]; do { in.read(by, 0, 1024); out.write(by); } while (in.available()>0); in.close(); out.close(); }catch(ArrayIndexOutOfBoundsException e) { e.printStackTrace(); }catch(IOException e) { e.printStackTrace(); } 2. try { FileInputStream in=new FileInputStream("C:/1.txt"); FileOutputStream out= new FileOutputStream("C:/2.txt"); BufferedInputStream bufferedIn=new BufferedInputStream(in); BufferedOutputStream bufferedOut=new BufferedOutputStream(out); byte[] by=new byte[1]; while (bufferedIn.read(by)!=-1) { bufferedOut.write(by); } //将缓冲区中的数据全部写出 bufferedOut.flush(); bufferedIn.close(); bufferedOut.close(); } catch (ArrayIndexOutOfBoundsException e) { // TODO: handle exception e.printStackTrace(); }catch (IOException e) { // TODO: handle exception e.printStackTrace(); }