龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

java文件复制代码片断(java实现文件拷贝)

时间:2014-06-01 16:00来源:网络整理 作者:网络 点击:
分享到:
本文介绍java实现文件拷贝的代码片断,大家可以直接放到程序里运行

代码如下:

try {
            File inputFile = new File(args[0]);
            if (!inputFile.exists()) {
                System.out.println("源文件不存在,程序终止");
                System.exit(1);
            }
            File outputFile = new File(args[1]);
            InputStream in = new FileInputStream(inputFile);
            OutputStream out = new FileOutputStream(outputFile);
            byte date[] = new byte[1024];
            int temp = 0;
            while ((temp = in.read(date)) != -1) {
                out.write(date);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

精彩图集

赞助商链接