Reading BFILE Data
To read BFILE data, you must first get the BFILE locator. You can get the locator
from either a callable statement or a result set.
Once you obtain the locator, you can invoke a number of methods on the BFILE
without opening it. For example, you can use the oracle.sql.BFILE methods
fileExists() and isFileOpen() to determine whether the BFILE exists and if
it is open. If you want to read and manipulate the data, however, you must open
and close the BFILE, as follows:
n Use the openFile() method of the oracle.sql.BFILE class to open a
BFILE.
n When you are done, use the closeFile() method of the BFILE class.
BFILE data is materialized as a Java stream. To read from a BFILE, use the
getBinaryStream() method of an oracle.sql.BFILE object to retrieve the
entire file as an input stream. This returns a java.io.InputStream object.
As with any InputStream object, use one of the overloaded read() methods to
read the file data, and use the close() method when you finish.
Example: Reading BFILE Data The following example uses the getBinaryStream()
method of an oracle.sql.BFILE object to read BFILE data into a byte stream and
then read the byte stream into a byte array. The example assumes that the BFILE has
already been opened.
// Read BFILE data from a BFILE locator
Inputstream in = bfile.getBinaryStream();
byte[] byte_array = new byte{10};
int byte_read = in.read(byte_array);
Notes:
n BFILEs are read-only. You cannot insert data or otherwise write
to a BFILE.
n You cannot use JDBC to create a new BFILE. They are created
only externally.
太长了,放不下了:(