Java:Clob 到字节 []

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5105065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:27:44  来源:igfitidea点击:

Java: Clob to byte[]

javasqlbytearrayclob

提问by Victor

How can I read a java.sql.Clob into a byte[]?

如何将 java.sql.Clob 读入字节 []?

回答by A.Alexander

with commons-io

使用公共资源

byte[] data = IOUtils.toByteArray(clob.getAsciiStream());

回答by Deepak

int length = clob.getLength();         
 byte[] array = new byte[length];       
 InputStream in = clob.getAsciiStream();       
 int offset = 0;        
 int n;        
 do      
    n = in.read(array, offset, length - offset);        
 while (n != -1);

Try the above snippet of code for reading a clob into Byte array.

尝试使用上面的代码片段将 clob 读入 Byte 数组。

回答by Nick

Get the ASCII stream and then read from the stream into a byte array. http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Clob.html#getAsciiStream()

获取 ASCII 流,然后从流中读取到字节数组中。http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Clob.html#getAsciiStream()