package IOTest;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class InOutPutStream {
public static void main(String [] args){
BufferedReader bufin = null;
BufferedWriter bufout = null;
try {
bufin = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\405784.jpg")));
bufout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("d:\\pic.jpg")));
char[] by = new char [1024];
int len =0;
// String line ="";
while((len=bufin.read(by))!=-1){
bufout.write(by,0,len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(bufin!=null){
try {
bufin.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(bufout!=null){
try {
bufout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
问什么我用转换流复制出来的字节文件不对呢?
|
|