Java活用生活

ログイン

オンライン状況

オンラインユーザー1人
ログインユーザー0人
登録ユーザー2人

カウンタ

COUNTER335463

日誌

MyDoc(備忘録) >> 記事詳細
2023/01/04

画像ファイルのコピー

固定リンク | by:aramaki
画像ファイルのコピー
------------------------------------
public class FileCopyTest {

private static String inPath = "D:/temp/test.jpg";

private static String outPath = "D:/temp/out.jpg";

public static void main(String[] args) {
try {
copy(inPath,outPath);
} catch (IOException e) {
System.out.println("エラー");
e.printStackTrace();
}

}
// バイナリファイルのコピー
private static void copy(String inPath,String outPath) throws IOException {
DataInputStream dataInStream = new DataInputStream(
new BufferedInputStream(
new FileInputStream(inPath)));
DataOutputStream dataOutStream = 
new DataOutputStream(
  new BufferedOutputStream(
    new FileOutputStream(outPath)));
int readByte=0;
int totalByte=0;
byte[] b=new byte[2048];
while(-1 != (readByte = dataInStream.read(b))){
dataOutStream.write(b, 0, readByte);
totalByte += readByte;
System.out.println("Read: " + readByte + " Total: " + totalByte);
}
dataInStream.close();
dataOutStream.close();
}
}
23:46 | 投票する | 投票数(0) | コメント(0)
Copyright © Java活用生活 All Rights Reserved .