Reading data from a file when it is written to

I use the proprietary Java library, which saves its data directly to java.io.File, but I need to be able to read the data so that it is directly transmitted. The data is binary, some media files.

java.io.Filepassed as an argument to this library, but I don't know how to get the stream from it. Is there an easy way to do this, besides opening the file for reading and trying to synchronize read / write operations !?

Presumably, I would like to skip writing to part of the file system, since I use this from the applet and in this case I need additional permissions.

+5
source share
2 answers

, , new FileInputStream(someFile) , . . flush(), .

, , , . :

FileInputStream input = new FileInputStream(file);
while (!Thread.currentThread().isInterrupted()) {
    byte[] bytes = new byte[1024];
    int readN = input.read(bytes);
    if (readN > 0) {
        byte[] sub = ArrayUtils.subarray(bytes, 0, readN);
        System.out.print("Read: " + Arrays.toString(sub) + "\n");
    }
    Thread.sleep(100);
}
+4

, , , , . , , (, ), java.io.RandomAccessFile

0

All Articles