Я написал цикл while для чтения данных из InPutStream и сохранения их в виде строки.
Но когда чтение завершено, пользовательский интерфейс моего приложения Windows зависает или зависает.
Я использовалКласс InputSteam и Scanner для чтения данных.
Вот код, который я использовал,
try{
// trying to send command to scanner to start scan
String strPushButtonCommand = "xx";
byte [] mValue = strPushButtonCommand.getBytes();
mOutPut.write(mValue);
writeToFile = new BufferedWriter(new FileWriter(filepath+
".txt"));
InputStream mInput = chosenPort.getInputStream();
Scanner input = new Scanner(mInput);
while(input.hasNextLine())
{
data = input.nextLine();
System.out.println(data);
writeToFile.write(data+"\n");
}
input.close();
System.out.println("print this message");
}catch(Exception error){
System.out.println(error);
}
В этом случае, пока цикл не выходит из цикла.