「Java ファイルコピー」の版間の差分
ナビゲーションに移動
検索に移動
| (同じ利用者による、間の1版が非表示) | |||
| 1行目: | 1行目: | ||
| − | ==Java ファイルコピー== | + | ==[[Java ファイルコピー]]== |
| − | [[Java]] | + | [[Java]] | |
=====例===== | =====例===== | ||
| 31行目: | 31行目: | ||
} catch(Exception e){ | } catch(Exception e){ | ||
| − | // | + | // [[Excel]]tion Handling |
} | } | ||
} | } | ||
} | } | ||
2020年2月16日 (日) 04:27時点における最新版
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 矢木浩人