忍者ブログ
Flex,Java,Html など、調べた事のメモ帳です。 間違ってたらゴメンなさい。
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ファイルのコピーは java.io.File では出来ません。自分で Stream を開いて、 入力から出力へデータを流し込む必要があります。


ソース記述例

public static void copy(File from, File to) throws IOException {
  BufferedOutputStream out = null;
  BufferedInputStream in = null;
  try {
    in = new BufferedInputStream(new FileInputStream(from));
    out = new BufferedOutputStream(new FileOutputStream(to));
    byte[] buff = new byte[4096];
    int len = 0;
    while ((len = in.read(buff, 0, buff.length)) >= 0) {
      out.write(buff, 0, len);
    }
  } finally {
    if (in != null) {
      try {
        in.close();
      } catch (IOException e) {
      }
    }
    if (out != null) {
      try {
        out.close();
      } catch (IOException e) {
      }
    }
  }
}
 



この記事にコメントする
name
title
color
mail
URL
comment
pass   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
secret (チェックを入れると管理人だけに表示できます)
この記事へのトラックバック
この記事にトラックバックする:
ブログランキング
にほんブログ村 IT技術ブログ IT技術メモへ
 
カレンダー
02 2024/03 04
S M T W T F S
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
人気ブログランキング
ブログランキング ブログランキング
最新TB
ブログ内検索
PR
ATOM  
ATOM 
RSS  
RSS 
Copyright ©   プログラムメモ   All Rights Reserved
Design by MMIT  Powered by NINJA TOOLS
忍者ブログ [PR]