java常用功能

1.复制文件

    private void fileChannelCopy(File source, File target) throws IOException {
        FileInputStream fi = null;
        FileOutputStream fo = null;
        FileChannel in = null;
        FileChannel out = null;
        
        try {
            fi = new FileInputStream(source);
            fo = new FileOutputStream(target);
            in = fi.getChannel();
            out = fo.getChannel();
            in.transferTo(0, in.size(), out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                 fi.close();
                 in.close();
                 fo.close();
                 out.close();
            } catch (IOException e) {
                LOGGER.error("File copy failed.", e);
            }      
        }
    }

 

你可能感兴趣的:(java常用功能)