Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从流中读取数据时,为什么我的程序挂起?_Android_File_Inputstream - Fatal编程技术网

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

Android 从流中读取数据时,为什么我的程序挂起?,android,file,inputstream,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 In

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

改进语法和代码格式以提高可读性您认为程序挂起是什么意思?在这个过程中,XML文件是什么样子的?