参照这个总结吧:- package com.tcptest;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class TestFuZ {
-
- public static void main(String[] args) {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- try
- {
- 复制后的图片 文件
- fos = new FileOutputStream("c:\\2.txt");
- //需要复制的 图片文件
- fis = new FileInputStream("c:\\1.txt");
- byte[] buf = new byte[1024];
- int len = 0;
- while((len=fis.read(buf))!=-1)
- {
- fos.write(buf,0,len);
- }
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制文件失败");
- }
- }
- }
复制代码 |