質問

I'm displaying streaming content using a file to buffer it (because it could be large enough to keep it in RAM). I have two threads: the first downloads a file from server and writes it to the local storage, and the second reads that file and displays the content.

The problem is, when the second thread reaches the end of the file, EOFException is thrown from DataInputStream.readFully() method. Is there any way to make it wait while the first thread writes enough data instead of throwing exception?

役に立ちましたか?

解決

Synchronize the threads. There's one possible approach.

他のヒント

Check for EOF before you read from the file. Or put a try ... catch(EOFException ex) around the read statement.

Have you tried using InputStream's available() method to get the number of bytes available and then using DataInputStream's read(byte[] b) with a byte[] the length of the number of bytes returned by available? I haven't actually tried this but it seems like it might work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top