在接收GPS终端发过来的数据后,发现0没了
本来设备号是:868120102014807 接收到后是86812121487 设备号中的0消失了
下面是源码,请各位帮忙看一下。听说是reader会让0消失,但我没用reader呀。
private static BufferedInputStream getBufferedInputStream(Socket socket){
try {
return new BufferedInputStream(socket.getInputStream());
} catch (IOException e) {
return null;
}
}
public static String String2Hex(String s){
String str = "";
for(int i=0;i<s.length();i++){
int ch = s.charAt(i);
String ss = Integer.toHexString(ch);
str = str + ss;
}
return str.toUpperCase();
}
private void doService() throws IOException{
while (true) {
Socket connection=null;
connection = server.accept();
InputStream in=getBufferedInputStream(connection);
byte[] tmp=new byte[1024];
int re=-1;
while((re=in.read(tmp))!=-1){
System.out.println(String2Hex(new String(tmp,0,re)));
}
}
}