从流中读取数据时,为什么我的程序会挂起?

时间:2015-11-29 16:33:44

标签: android file inputstream

从流中读取数据时,我正在写入新创建的临时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);
  }
}

0 个答案:

没有答案