你好,我给你看了下,有一处错误
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class tt {
- public static void main(String args ){//这里少了一个[ ],加上就OK了,我运行了下,复制完成了,没有错了!!
- copyPci();
- }
- public static void copyPci(){
- FileInputStream fis = null; //生成字节输入流引用fis,赋值为空;
- FileOutputStream fos = null; //生成字节输出流引用fos,赋值为空;
-
- try{
- fis = new FileInputStream("1.jpg");
- fos = new FileOutputStream("to.jpg");
-
- int len;
- byte buffer [] = new byte[1024];
-
- while(true){
-
- len = fis.read(buffer);
- if(len == -1)
- break;
- fos.write(buffer,0,len);
- }
- System.out.println("复制完成");
-
-
- }
- catch(IOException e){
- System.out.println(e);
- }
-
- finally{
- try{
- if(fis != null)
- fis.close();
- if(fos != null)
- fos.close();
- }
- catch(IOException e){
- System.out.println(e);
- }
- }
-
- }
- }
复制代码 |