File/IO流如何复制图片

怎么使用File/IO复制图片,以下是我写的代码,总是报拒绝访问,请各位哥哥们帮忙看下,谢谢

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**

  • 使用io流复制图片
  • @author Administrator * */ public class IoPicture { public static void main(String[] args) { FileInputStream fis=null; BufferedInputStream bis=null; FileOutputStream fos=null; BufferedOutputStream bos= null; try { fis=new FileInputStream("D:/Pictures/lzj.jpeg"); bis=new BufferedInputStream(fis); fos=new FileOutputStream("F:/工作空间"); bos=new BufferedOutputStream(fos); byte[] bys = new byte[1024];
    int len = 0;
    while ((len = bis.read(bys)) != -1) {
    bos.write(bys, 0, len);
    len=bis.read(bys); }
    bos.flush(); bos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if(bis!=null){ bis.close(); } if(fis!=null){ fis.close(); } } catch (IOException e2) { // TODO: handle exception e2.printStackTrace(); } } } }

fos=new FileOutputStream("F:/工作空间");这些的有问题啊 工作空间是文件夹?

FileOutputStream 构造函数 不给是 文件夹哦

  • @param name the system-dependent filename
    • @exception FileNotFoundException **if the file exists but is a directory
    • rather than a regular file**, does not exist but cannot
    • be created, or cannot be opened for any other reason
    • @exception SecurityException if a security manager exists and its
    • checkWrite method denies write access
    • to the file.
    • @see java.lang.SecurityManager#checkWrite(java.lang.String) */ public FileOutputStream(String name) throws FileNotFoundException { this(name != null ? new File(name) : null, false); }