本帖最后由 陌路行者 于 2013-7-8 20:28 编辑
- import java.io.*;
- class CopyPic
- {
- public static void main(String[] args)
- {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- BufferedOutputStream bufos = null;
- BufferedInputStream bufis = null;
- try
- {
- bufis = new BufferedInputStream(new FileInputStream("1.jpg"));
- bufos = new BufferedOutputStream(new FileOutputStream("2.jpg"));
- int by = 0;
- while((by=bufis.read())!=-1)
- {
- bufos.write(by);
- }
- //byte[] chs = new byte[1024];
- //int len =0;
- //while((len=fis.read(chs))!=-1)
- //{
- //fos.write(chs,0,len);
- //}
- }
- catch (IOException e)
- {
- throw new RuntimeException("读写文件失败");
- }
- finally
- {
- try
- {
- fis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取文件关闭失败");
- }
- try
- {
- fis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入文件关闭失败");
- }
- }
- }
- }
复制代码
为什么会丢失数据
|