1. JDK7之前的处理
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream("美女.jpg");
fos = new FileOutputStream("d:\\meinv.jpg");
byte[] bys = new byte[1024];
int len;
while ((len = fis.read(bys)) != -1) {
fos.write(bys,0,len);
}
} catch (IOException e) {
} finally {
try {
if(fis!=null)
fis.close();
} catch (IOException e) {
}
try {
if(fos!=null)
fos.close();
} catch (IOException e) {
}
}
2. JDK7之后的处理
try(
FileInputStream fis = new FileInputStream("美女.jpg");
FileOutputStream fos = new FileOutputStream("d:\\meinv.jpg");
) {
byte[] bys = new byte[1024];
int len;
while ((len = fis.read(bys)) != -1) {
fos.write(bys,0,len);
}
} catch (IOException e) {
}
|
|