刘俊佳 发表于 2012-7-12 17:50
我C盘下有图片的并且图片的文件名是1.bmp - package practice;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- public class CopyPic {
- public static void main(String[] args) {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- try {
- fos = new FileOutputStream("c:\\2.bmp");
- fis = new FileInputStream("c:\\1.bmp");
- byte[] buf=new byte[1024];
- int len=0;
- while((len=fis.read(buf))!=-1)
- {
- fos.write(buf,0,len);
- }
- } catch (Exception e) {
- throw new RuntimeException("复制文件失败");
- }
- finally
- {
- try
- {
- if(fis!=null)
- fis.close();
- }
- catch(Exception e)
- {
- throw new RuntimeException("读取关闭失败");
- }
- try
- {
- if(fos!=null)
- fos.close();
- }
- catch(Exception e)
- {
- throw new RuntimeException("写入关闭失败");
- }
- }
- }
- }
复制代码 你的代码,我C盘下运行前后的截图: |
|