コード例 #1
0
ファイル: FileUtil.java プロジェクト: norain2050/xtv_player
  public static boolean copy(File from, File to) {
    if (from == null || to == null) {
      return false;
    }

    if (to.exists()) {
      if (!to.delete()) {
        return false;
      }
    }

    if (from.exists() && from.isFile()) {
      InputStream is = null;
      OutputStream os = null;
      try {
        is = new FileInputStream(from);
        os = new FileOutputStream(to);
      } catch (FileNotFoundException e) {
        return false;
      } finally {
        closeQuietly(is);
        closeQuietly(os);
      }
      return copy(is, os);
    }

    return false;
  }
コード例 #2
0
ファイル: FileUtil.java プロジェクト: norain2050/xtv_player
 public static boolean copy(InputStream from, OutputStream to) {
   DataInputStream dis = null;
   DataOutputStream dos = null;
   try {
     dis = new DataInputStream(from);
     dos = new DataOutputStream(to);
     int length = 0;
     byte[] buffer = new byte[1024];
     while ((length = dis.read(buffer, 0, buffer.length)) > 0) {
       dos.write(buffer, 0, length);
     }
     return true;
   } catch (IOException e) {
     return false;
   } finally {
     closeQuietly(dis);
     closeQuietly(dos);
   }
 }