本帖最后由 ㄗ灬Night|K 于 2013-10-4 14:21 编辑
为什么程序在编译时OK,运行时却显示“复制失败”呢?- //复制一张图片
- import java.io.*;
- class CopyPic
- {
- public static void main(String[] args)
- {
- FileInputStream fis = null;
- FileOutputStream fos = null;
-
- try
- {
- fis = new FileInputStream("C:\\111");
- fos = new FileOutputStream("C:\\222");
- byte[] by = new byte[1024];
- int num = 0;
- while ((num = fis.read(by))!=-1)
- {
- fos.write(by,0,num);
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制失败");
- }
- finally
- {
- try
- {
- if (fis!=null)
- fis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取关闭出错");
- }
- try
- {
- if (fos!=null)
- fos.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入关闭出错");
- }
- }
- }
- }
复制代码 |
-
1.jpg
(19.87 KB, 下载次数: 24)
-
2.jpg
(39.98 KB, 下载次数: 28)
c盘中的图片
|