本帖最后由 黑马-王鹏 于 2013-4-8 12:32 编辑
- //需求:从d盘复制图片到e盘
- import java.io.*;
- class CopyPicture
- {
- public static void main(String[] args)
- {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- try
- { //创建目的文件
- fos = new FileOutputStream("e:\\kobe24.jpg");
- //创建关联文件
- fis = new FileInputStream("d:\\kobe.jpg");
- byte [] bt = new byte[1024];
- int len = 0;
- while ((len=fis.read(bt))!=-1)
- {
- fos.write(bt);
- }
- }
- 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("图片写入异常");
- }
- }
- }
- }
复制代码 为什么图片拷贝之后会大1KB啊?
|
|