IO编程——文件复制操作

来源:互联网 发布:计算机c语言基础知识 编辑:程序博客网 时间:2024/04/28 15:01

将某个文件复制到指定目录。

package com.file;import java.io.*;public class test4 {public static void main(String[] args) {FileInputStream fis = null;FileOutputStream fos =null;try {fis = new FileInputStream("d:\\qlg.jpg");fos = new FileOutputStream("e:\\qlg_复件.jpg");byte []buf = new byte[1024]; int n = 0;while ((n=fis.read(buf)) != -1){fos.write(buf);//输出到指定文件}} catch (Exception e) {// TODO 自动生成的 catch 块e.printStackTrace();}finally{//关闭流try {fis.close();fos.close();} catch (IOException e) {// TODO 自动生成的 catch 块e.printStackTrace();}}}}


0 0
原创粉丝点击