Home > Back-end >  With byte input/output stream copy pictures, why show unable to open the picture, because the image
With byte input/output stream copy pictures, why show unable to open the picture, because the image

Time:12-11

Copy pictures show a success, but open the said damaged, see the copy pictures found only 4 bytes,

CodePudding user response:

Copy the picture is actually accomplished by input and output flow of file to the file
in reading and writingWriting is byte or character,
You look at your code accept=fip. Read ()
Accept you as the int type, then you write is the subscript, each byte read not write section, so you copy pictures are damaged
Fip. Read () returns the subscript for each of the writing, you want to switch to byte array, can write bytes
Below is I wrote before, I use the character of stream, you have to do is replace chars with an array of bytes, you can refer to the
 InputStreamReader isr=null; 
Try {
//used by copyFile (" C: \ \ Users \ \ Administrator \ \ Desktop \ \ test TXT ", "C: \ \ Users \ \ Administrator \ \ Desktop \ \ test_copy TXT", false);
The File File=new File (" C: \ \ Users \ \ Administrator \ \ Desktop \ \ test TXT ");
Isr=new InputStreamReader (new FileInputStream (file), "utf-8");
Char [] chars=new char [1024].

While (isr) read (chars)!=1) {
System. The out. Println (new String (" GBK ", chars));
}
} the catch (Exception e) {
e.printStackTrace();
} the finally {
Try {
Isr. The close ();
} the catch (IOException e) {
e.printStackTrace();
}
}

CodePudding user response:

Why can I run

CodePudding user response:

CodePudding user response:

No problem I copied this picture

CodePudding user response:

I am also the same problem you found the solution?
  • Related