byte[]轉String後,去掉String後面的空字元
阿新 • • 發佈:2020-12-28
技術標籤:Java
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(); } }
結果: