Adding non printable chars to a string in Java?

前端 未结 3 530
傲寒
傲寒 2020-12-19 09:59

I need to add some non printable chars to a string in java so it can be sent down a tcp pipe. the chars mean something to the protocol I am using (record separator and end o

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 10:21

    If you wish, you can write these as Unicode literals (in chars or Strings):

    final String endOfText = "\u0003";
    
    • Unicode charts
    • Java Language Specification Lexical Structure chapter

    I am assuming that you don't literally want ASCII for a byte-based protocol (the chars are still 16 bits).

提交回复
热议问题