例一、
package inOutJava;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class FileDo {
public static void main(String args[]){
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
BufferedInputStream reader = null;
BufferedOutputStream writer = null;
try{
try{
fileIn = new FileInputStream("d://tzj.jpg");
fileOut = new FileOutputStream("d://tzj_1.jpg");
reader = new BufferedInputStream(fileIn);
writer = new BufferedOutputStream(fileOut);
int rs= 0;
byte[] by = new byte[1024*100];
rs=reader.read(by);
writer.write(by,0,rs);
}finally{
reader.close();
fileIn.close();
writer.close();
fileOut.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
例二、
package inOutJava;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class FileDo {
public static void main(String args[]){
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
BufferedInputStream reader = null;
BufferedOutputStream writer = null;
try{
try{
fileIn = new FileInputStream("d://tzj.jpg");
fileOut = new FileOutputStream("d://tzj_1.jpg");
reader = new BufferedInputStream(fileIn);
writer = new BufferedOutputStream(fileOut);
int rs= 0;
byte[] by = new byte[1024];
while((rs = reader.read(by)) > 0){
writer.write(by,0,rs);
}
}finally{
reader.close();
fileIn.close();
writer.close();
fileOut.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}