- public class TestFileCopy {
- public static void main(String[] args) {
- FileInputStream fis;
- try {
- // 数据源文件
- fis = new FileInputStream("aaa.txt");
- // 数据目的文件
- FileOutputStream fos = new FileOutputStream("bbb.txt");
- byte[] buf = new byte[1024];
- int len = 0;
- while((len = fis.read(buf))!=-1) {
- fos.write(buf,0,len);
- }
- // int b = 0;
- // while((b = fis.read())!=0) {
- // fos.write(b);
- //
- }
- if(fos!=null) {
- fos.close();
- }
- if (fis!=null) {
- fis.close();
- }
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
来源: http://www.bubuko.com/infodetail-3281361.html