所以我正在使用TCP,我从DataInputStream获得了数据,但是当我获得数据时,它周围有^X^@^E^R之类的东西。当它不应该这样做的时候。有没有什么我可以去掉的。不过,它需要是动态的。
DataInputStream dataIn = new DataInputStream(socket.getInputStream());
StringBuffer inputLine = new StringBuffer();
String tmp;
while((tmp = dataIn.readLine()) != null){
//tmp = Normalizer.normalize(tmp, Normalizer.Form.NFD);
inputLine.append(tmp);
logText(tmp);
}发布于 2015-05-26 05:17:27
DataInputStream.readLine()已弃用。请改用BufferedReader。
例如:BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
我是如何读行的:
while ((socket != null) && !(socket.isClosed())) {
// read in a line but only if there is one - blocks here till there is a line
String clientSentence = input.readLine();
if ((clientSentence != null) && (!(clientSentence.equals("")))) {
// do something
}
}发布于 2015-05-26 05:38:07
要删除所有控制字符(十进制32以下的字节),可以执行以下操作:
tmp = tmp.replaceAll("[\000-\01F]", "");https://stackoverflow.com/questions/30445932
复制相似问题