|
抄的以下代码:
- //-----------Class CopyFile Begin---------
- //Class CopyFile
- //CopyRight:Writed By Yun-Fengsheng
- //Last modify time:2001-11-16
- //Method: public boolean copy(String from_filename,String to_filename)
- class CopyFile
- {
- public boolean copy(String file1,String file2)
- {
- try //must try and catch,otherwide will compile error
- {
- //instance the File as file_in and file_out
- java.io.File file_in=new java.io.File(file1);
- java.io.File file_out=new java.io.File(file2);
- FileInputStream in1=new FileInputStream(file_in);
- FileOutputStream out1=new FileOutputStream(file_out);
- byte[] bytes=new byte[1024];
- int c;
- while((c=in1.read(bytes))!=-1)
- out1.write(bytes,0,c);
- in1.close();
- out1.close();
- return(true); //if success then return true
- }
- catch(Exception e)
- {
- System.out.println("Error!");
- return(false); //if fail then return false
- }
- }
- }
- //Class CopyFile Example
- /*
- CopyFile copy1=new CopyFile();
- boolean copy_ok=copy1.copy("c:/hello.jsp","c:/hello_backup.jsp");
- if(copy_ok)
- {
- out.println("拷贝成功!");
- }else
- {
- out.println("拷贝失败!");
- }
- */
- //-----------Class CopyFile End-----------
复制代码
结果,编译错误:
- D:\java>javac CopyFile.java
- CopyFile.java:16: cannot resolve symbol
- symbol : class FileInputStream
- location: class CopyFile
- FileInputStream in1=new FileInputStream(file_in);
- ^
- CopyFile.java:16: cannot resolve symbol
- symbol : class FileInputStream
- location: class CopyFile
- FileInputStream in1=new FileInputStream(file_in);
- ^
- CopyFile.java:17: cannot resolve symbol
- symbol : class FileOutputStream
- location: class CopyFile
- FileOutputStream out1=new FileOutputStream(file_out);
- ^
- CopyFile.java:17: cannot resolve symbol
- symbol : class FileOutputStream
- location: class CopyFile
- FileOutputStream out1=new FileOutputStream(file_out);
- ^
- 4 errors
复制代码
抄的代码,应该不会有错吧。 |
|