Is there any way to get the size in bytes of a string in Java?

前端 未结 5 766
旧巷少年郎
旧巷少年郎 2021-01-21 19:20

I need the size in bytes of each line in a file, so I can get a percentage of the file read. I already got the size of the file with file.length(), but how do I get

5条回答
  •  旧时难觅i
    2021-01-21 19:54

    final String hello_str = "Hello World";
    
    hello_str.getBytes().length is the "byte size", i.e. the number of bytes
    

提交回复
热议问题