forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyImage.java
More file actions
26 lines (19 loc) · 710 Bytes
/
CopyImage.java
File metadata and controls
26 lines (19 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.zetcode;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyImage {
public static void main(String[] args) throws IOException {
var sourceFile = "src/resources/sid.jpg";
var destFile = "src/resources/sid2.jpg";
try (var fis = new FileInputStream(sourceFile);
var fos = new FileOutputStream(destFile)) {
byte[] buffer = new byte[1024];
int noOfBytes = 0;
// read bytes from source file and write to destination file
while ((noOfBytes = fis.read(buffer)) != -1) {
fos.write(buffer, 0, noOfBytes);
}
}
}
}