LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 681|回复: 1

初学java,问一个菜问题。

[复制链接]
发表于 2005-3-25 15:47:11 | 显示全部楼层 |阅读模式
抄的以下代码:

  1. //-----------Class CopyFile Begin---------
  2. //Class CopyFile
  3. //CopyRight:Writed By Yun-Fengsheng
  4. //Last modify time:2001-11-16
  5. //Method: public boolean copy(String from_filename,String to_filename)

  6. class CopyFile
  7. {
  8.     public boolean copy(String file1,String file2)
  9.     {
  10.         try //must try and catch,otherwide will compile error
  11.         {
  12.             //instance the File as file_in and file_out
  13.             java.io.File file_in=new java.io.File(file1);
  14.             java.io.File file_out=new java.io.File(file2);
  15.             FileInputStream in1=new FileInputStream(file_in);
  16.             FileOutputStream out1=new FileOutputStream(file_out);
  17.             byte[] bytes=new byte[1024];
  18.             int c;
  19.             while((c=in1.read(bytes))!=-1)
  20.                 out1.write(bytes,0,c);
  21.             in1.close();
  22.             out1.close();
  23.             return(true); //if success then return true
  24.         }

  25.         catch(Exception e)
  26.         {
  27.             System.out.println("Error!");
  28.             return(false); //if fail then return false
  29.         }
  30.     }
  31. }

  32. //Class CopyFile Example
  33. /*
  34. CopyFile copy1=new CopyFile();
  35. boolean copy_ok=copy1.copy("c:/hello.jsp","c:/hello_backup.jsp");
  36. if(copy_ok)
  37. {
  38.     out.println("拷贝成功!");
  39. }else
  40. {
  41.     out.println("拷贝失败!");
  42. }
  43. */
  44. //-----------Class CopyFile End-----------
复制代码


结果,编译错误:

  1. D:\java>javac CopyFile.java
  2. CopyFile.java:16: cannot resolve symbol
  3. symbol  : class FileInputStream
  4. location: class CopyFile
  5.             FileInputStream in1=new FileInputStream(file_in);
  6.             ^
  7. CopyFile.java:16: cannot resolve symbol
  8. symbol  : class FileInputStream
  9. location: class CopyFile
  10.             FileInputStream in1=new FileInputStream(file_in);
  11.                                     ^
  12. CopyFile.java:17: cannot resolve symbol
  13. symbol  : class FileOutputStream
  14. location: class CopyFile
  15.             FileOutputStream out1=new FileOutputStream(file_out);
  16.             ^
  17. CopyFile.java:17: cannot resolve symbol
  18. symbol  : class FileOutputStream
  19. location: class CopyFile
  20.             FileOutputStream out1=new FileOutputStream(file_out);
  21.                                       ^
  22. 4 errors
复制代码


抄的代码,应该不会有错吧。
发表于 2005-3-25 19:07:17 | 显示全部楼层
import java.io.*
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表