Topic: 求助:下面的程序哪错了?编不过去! |
Print this page |
1.求助:下面的程序哪错了?编不过去! | Copy to clipboard |
Posted by: skymysky777 Posted on: 2005-06-15 10:37 下面实现的是两个文件复制,我是初学者,这段程序编不过去.还请高手指点. import java.io.*; public class examFile1 { public static void main(String arg[]) { FileInputStream ins; FileInputStream outs; File fileObject2 = new File("d:\\zzz","fstFile.txt"); try { fileObject2.createNewFile(); ins = new FileInputStream("d:\\zzz\\123.txt"); outs = new FileInputStream("d:\\zzz\\fstFile.txt"); copyContent(ins,outs); }catch(FileNotFoundException e) { } catch(IOException e){ } } static void copyContent(FileInputStream inobj,FileOutputStream outobj){ int copyLen; byte[] copyBuf = new byte[1024]; try{ while((copyLen = inobj.read(copyBuf,0,1024))!=-1){ String copyStr= new String(copyBuf); System.out.println(copyStr); outObj.write(copyBuf,0,copyLen); } } catch(IOException e){ System.out.println("asf"+e); } } } |
2.Re:求助:下面的程序哪错了?编不过去! [Re: skymysky777] | Copy to clipboard |
Posted by: snowbird2005 Posted on: 2005-06-15 10:44 FileInputStream outs? 将所有outs对应的FileInputStream该为FileOutputStream. |
3.Re:求助:下面的程序哪错了?编不过去! [Re: skymysky777] | Copy to clipboard |
Posted by: skymysky777 Posted on: 2005-06-15 10:51 谢谢指教! 是自己的马虎造成的~ 总结:1\编程时要细心输入! 2\遇到问题要冷静~ 谢谢SNOWBIRD2005 |
4.Re:求助:下面的程序哪错了?编不过去! [Re: skymysky777] | Copy to clipboard |
Posted by: skymysky777 Posted on: 2005-06-15 10:57 static void copyContent(FileInputStream inobj,FileOutputStream outobj){ int copyLen; byte[] copyBuf = new byte[1024]; try{ while((copyLen = inobj.read(copyBuf,0,1024))!=-1){ 程序中的这里有点不明白~~~请指点.... 为什么要用BYTE[] ?????/?用别的不行吗? |
5.Re:求助:下面的程序哪错了?编不过去! [Re: skymysky777] | Copy to clipboard |
Posted by: why Posted on: 2005-06-15 12:12 skymysky777 wrote: FileInputStream only has this. http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html#read(byte[]) |
6.Re:求助:下面的程序哪错了?编不过去! [Re: skymysky777] | Copy to clipboard |
Posted by: skymysky777 Posted on: 2005-06-15 12:47 谢过~! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |