画像ファイルのコピー
------------------------------------
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();
}
}