从流中读取数据时,我正在写入新创建的临时XML文件。但程序挂起了。
我在这里错过了什么?
if (deviceSocket.isConnected()) {
OutputStream os = deviceSocket.getOutputStream();
os.write(xmlStr.getBytes());
os.flush();
// Read Response from Socket
respFromDevice = new BufferedReader(new InputStreamReader(deviceSocket.getInputStream()));
FileWriter fileWriter = null;
// Write into temp xml file
String response;
while ((response = respFromDevice.readLine()) != null) {
sb.append(response);
File newTextFile = new File("tmp.xml");
fileWriter = new FileWriter(newTextFile);
fileWriter.write(sb.toString());
//Files.write(Paths.get("temp.xml"), sb.toString().getBytes());
System.out.println(response);
}
}