Hi
I have a xml file which is stored in a BLOB type in Oracle . Can anybody tell me how can I convert that into a physical file.
I read the data using inpstream and the question is how to convert or cast it in a physical file.
Any sample code would be highly appreciated
Thanks
Asad
-
Converting InputStream into File (2 messages)
- Posted by: Asad Aziz
- Posted on: May 15 2001 16:04 EDT
Threaded Messages (2)
- Converting InputStream into File by Andy Nguyen on May 16 2001 13:27 EDT
- Converting InputStream into File by Asad Aziz on May 16 2001 15:50 EDT
-
Converting InputStream into File[ Go to top ]
- Posted by: Andy Nguyen
- Posted on: May 16 2001 13:27 EDT
- in response to Asad Aziz
There may be a more elegant way to do it, but this should work:
String fileName = "...";
InputStream xml = /* from BLOB */;
BufferedInputStream bis = new BufferendInputStream(xml);
FileOutputStream fos = new FileOutputStream(fileName);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int bufferSize = 1024; // 1KB buffer
int totalRead = 0;
int read = 0;
byte[] b = new byte[bufferSize];
while ((read = bis.read(b, 0, bufferSize)) > 0) {
bos.write(b, totalRead, read);
totalRead += read;
}
bos.close(); // should flush the stream and close fos also
bis.close();
Of course, you're gonna have to handle all of the exceptions that can be thrown in the above code, but it's a starting point. Hope this helps.
Andy -
Converting InputStream into File[ Go to top ]
- Posted by: Asad Aziz
- Posted on: May 16 2001 15:50 EDT
- in response to Andy Nguyen
Hi Andy
Thanks a lot. It works. Do u think using PrintStream would be better, because this way it adds some junk words in the beginning of XML file.
ThankYou
Bye
Asad