本帖最后由 钟成军 于 2014-4-12 12:00 编辑
楼主你复制图片,只能用字节流,四个相关的类是
BufferedInputStream,BufferedOutputStream,FileInputStream,OutputStream
- import java.io.*;
- class CopyPic
- {
- public static void main(String[] args)
- {
- BufferedInputStream in = null;
- BufferedOutputStream out = null;
- File src = new File("c:\\1.png");
- File dir = new File("d:\\2.png");
- try
- {
- in = new BufferedInputStream(new FileInputStream(src));
- out = new BufferedOutputStream(new FileOutputStream(dir));
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = in.read(buf))!=-1)
- {
- out.write(buf,0,len);
- out.flush();
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制失败");
- }
- finally
- {
- try
- {
- if(in!=null)
- in.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取失败");
- }
- try
- {
- if(out!=null)
- out.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入失败");
- }
- }
- }
- }
复制代码
|