Java ファイルコピー
ナビゲーションに移動
検索に移動
Java ファイルコピー
Java |
例
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; public class FileCopySample { public static void main(String[] args) { try { byte[] buf = new byte[1024]; int ret = -1; File file = new File("/home/hoge/sourcefile.txt"); File outFile = new File("/home/hoge/destfile.txt"); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile)); while((ret = in.read(buf)) > 0) { out.write(buf,0,ret); out.flush(); } out.flush(); in.close(); out.close(); } catch(Exception e){ // Exceltion Handling } } }
© 2006 矢木浩人