这样写Socket 是否可以?这样写Socket 是否可以?
try(Socket socket= serverSocket.accept();
InputStream inputStream = socket.getInputStream()) {
byte[] bytes = new byte[1024];
int len = 0;
int bytesWritten = 0;
StringBuilder sb = new StringBuilder();
while ((len = inputStream.read(bytes)) != -1) {
//注意指定编码格式,发送方和接收方一定要统一,建议使用UTF-8
sb.append(new String(bytes, 0, len, "GB2312"));
bytesWritten += len;
}
String str = sb.toString();
String result = str.substring(38, str.length() - 3);
System.out.println(result);
dealMessage t = new dealMessage();
t.JdbcDemo(result);
} catch (Exception e) {
System.out.println("e.toString()打印结果: "+ e.toString());
System.out.println("e.getMessage()打印结果: "+ e.getMessage());
System.out.println("============分割线=============");
e.printStackTrace();
System.out.println("============分割线=============");
}
```