Java プログラムメモ


トップ

ファイルのコピー方法

ファイルのコピーは 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) { } } } }

プログラムメモ アフリカ雑貨や農作物のセレクトショップ - はろの屋 マゴソスクール クラウドファンディング
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送