Here you can find the source of copyFile(String src, String tar)
Parameter | Description |
---|---|
src | a parameter |
tar | a parameter |
public static int copyFile(String src, String tar)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**//from ww w .j av a 2 s. c o m * copyFile * * @param src * @param tar * @return */ public static int copyFile(String src, String tar) { int res = 0; File srcFile = new File(src); if (srcFile.exists()) { try { byte[] data = readFile(src); writeFile(tar, data, false); res = 1; } catch (Exception ee) { // ignore } } return res; } /** * existFile * * @param path * @return */ public static boolean exists(String path) { try { File temp = new File(path); return temp.exists(); } catch (Exception e) { // ignore } return false; } /** * readFile * * @param destination * @return * @throws IOException */ public static byte[] readFile(String destination) throws IOException { File temp = new File(destination); if (temp.exists()) { FileInputStream fis = new FileInputStream(temp); byte[] data = new byte[(int) temp.length()]; try { fis.read(data); } finally { fis.close(); } return data; } return new byte[0]; } /** * writeFile * * @param destination * @param data * @throws IOException */ public static void writeFile(String destination, byte[] data, boolean append) throws IOException { File temp = new File(destination); if (temp.exists() && append == true) { FileOutputStream fos = new FileOutputStream(temp, true); try { fos.write(data); fos.flush(); } finally { fos.close(); } } else { FileOutputStream fos = new FileOutputStream(temp); try { fos.write(data); fos.flush(); } finally { fos.close(); } } } }