package com.heilong.io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class copy_image {
public static void main(String[] args){
copyImage1();
}
public static void copyImage3(){
FileReader fileReader = null;
FileWriter fileWriter = null;
try {
File inFile = new File("./src/data/1.0.PNG");
File destFile = new File("./src/data/1.0.copy3.PNG");
fileReader = new FileReader(inFile);
fileWriter = new FileWriter(destFile);
char[] buf = new char[1024];
int length = 0;
while((length=fileReader.read(buf)) != -1){
fileWriter.write(buf, 0, length);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void copyImage2(){
BufferedInputStream bufferedInputStream = null;
BufferedOutputStream bufferedOutputStream = null;
try {
File infile = new File("./src/data/1.0.PNG");
File destFile = new File("./src/data/1.0.copy2.PNG");
FileInputStream fileInputStream = new FileInputStream(infile);
FileOutputStream fileOutputStream = new FileOutputStream(destFile);
bufferedInputStream = new BufferedInputStream(fileInputStream);
bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
int content = 0;
while((content=bufferedInputStream.read()) != -1){
bufferedOutputStream.write(content);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
bufferedOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
bufferedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void copyImage1() {
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
File inFile = new File("./src/data/1.0.PNG");
File destFile = new File("./src/data/1.0._copy1.PNG");
fileInputStream = new FileInputStream(inFile);
fileOutputStream = new FileOutputStream(destFile);
byte[] buf = new byte[1024];
int length = 0;
while((length=fileInputStream.read(buf)) != -1){
fileOutputStream.write(buf, 0, length);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}