コンテンツをファイルに書き込もうとしていますが、while ループがすべての行を出力すると、スタックして次の行に進みません。while ループの次の行は実行されていません。私の最初の推測では、fstream はまだ別の行を待っている可能性がありますが、while ループはそれ以上データがないかどうかを確認してから、それが出てくるはずです。
ここで私を助けてください!ありがとう。
//コード
File file;
DataInputStream inputData = new DataInputStream(newPeerConnection.getInputStream());
file = new File(
"F:\\Workspace\\PeerToPeer\\src\\ncsu\\csc\\socketClasses\\out\\out.txt");
@SuppressWarnings("resource")
PrintWriter fstream = new PrintWriter(new FileWriter(
file, true));
if (!file.exists()) {
file.createNewFile();
}
System.out.println("Writing to file: ");
while ((strval = inputData.readUTF()) != null) {
System.out.println(strval);
fstream.println(strval);
//fstream.flush();
//fstream.close();
}
//These lines are not executed
System.out.println("Do you want to download another file (Y/N)?");
wantToContinue = scannerObj.next();
out.writeUTF(wantToContinue);
out.flush();}