Two identical files have different file size based on the way it is written from C#

前端 未结 1 1437
栀梦
栀梦 2021-01-14 06:21

I am trying to write to a file an array of object serialised into JSON format. I am trying to write it in two different way as shown below.

ToSerialise[] Ob         


        
相关标签:
1条回答
  • 2021-01-14 06:44

    Even though the content of both the files are same, they have different file size.

    If they have a different size, then they definitely have different contents. A file is (pretty much) just a sequence of bytes - and if two sequences have different lengths, they're different sequences.

    In this case, the two files both represent the same text, but using different encodings - file2 will use UTF-8, and file1 will use UTF-16.

    To think of it a different way: if you saved the same picture to two files, one as JPEG and one as PNG, would you expect the files to be the same size?

    0 讨论(0)
提交回复
热议问题