欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

使用apache commons的FileUtils复制文件,,package cn.o

来源: javaer 分享于  点击 16990 次 点评:218

使用apache commons的FileUtils复制文件,,package cn.o


package cn.outofmemory.snippets.core;import java.io.File;import java.io.IOException;import org.apache.commons.io.FileUtils;public class FileCopy {    public static void main(String[] args) {        // We take a reference to original .txt        File file1 = new File("test.txt");        // We take a reference to the copy .txt        File file2 = new File("test(copy).txt");        try {            // We copy the file with copyFile method            FileUtils.copyFile(file1, file2);            // We compare the files to test the result            String content1 = FileUtils.readFileToString(file1);            String content2 = FileUtils.readFileToString(file2);            System.out.println("Content of file 1: " + content1);            System.out.println("Content of file 2: " + content2);        } catch (IOException e) {            e.printStackTrace();        }    }}
相关栏目:

用户点评