FileInputStream vs FileReader

后端 未结 6 808
庸人自扰
庸人自扰 2020-11-28 04:32
FileReader rd=new FileReader(\"new.mp4\");
FileWriter wr=new FileWriter(\"output.mp4\");
int ch;
while((ch=rd.read())!=-1)
  wr.write(ch);

wr.flush();
wr.close();
<         


        
6条回答
  •  一向
    一向 (楼主)
    2020-11-28 04:37

    FileInputStream is used for reading streams of raw bytes of data, like raw images. FileReaders, on the other hand, are used for reading streams of characters

    The difference between FileInputStream and FileReader is, FileInputStream reads the file byte by byte and FileReader reads the file character by character.

    So when you are trying to read the file which contains the character "Č", in FileInputStream will give the result as 196 140, because the ASCII value of Č is 268.

    In FileReader will give the result as 268 which is the ASCII value of the char Č.

提交回复
热议问题