显示文件损坏
public static void main(String[] args) {
// TODO Auto-generated method stub
copyPic("d:\\00\\1.png");
}
public static void copyPic(String pathName){
BufferedReader bi=null;
BufferedOutputStream bo=null;
try {
//转换流 使用readLine方法。
InputStreamReader ins = new InputStreamReader(new FileInputStream(pathName));
bo= new BufferedOutputStream(new FileOutputStream("d:\\1.png"));
bi= new BufferedReader(ins);
// byte[] buf = new byte[1024*1024];
String line=null;
while((line=bi.readLine())!=null){
bo.write(line.getBytes());
bo.flush();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
//关闭资源
if(bi!=null){
try {
bi.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(bo!=null){
try {
bo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
} |