After byte[] is converted to String, remove the null character after String

public static void main(String[] args) {
        byte[] readBuffer = new byte[1024*1024];
        try {
            String flightInfo=new String(readBuffer,"UTF-8");
            int length=flightInfo.length();
            System.out.println(length);
            flightInfo=flightInfo.trim();//通过trim去掉空字符
            int length2=flightInfo.length();
            System.out.println(length2);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
}

result: 

Guess you like

Origin blog.csdn.net/hzkcsdnmm/article/details/111556434