Read varbinary data in java
Posted
by
masoud farahani
on Stack Overflow
See other posts from Stack Overflow
or by masoud farahani
Published on 2012-06-16T11:07:23Z
Indexed on
2012/06/16
15:16 UTC
Read the original article
Hit count: 209
I made a Java application which reads some files from SQL server.
Those files are saved to a varbinary(MAX)
field in SQL Server by a third party web service.
My problem is that when I want to read those files with my Java application, those binary data show different content in the Java application. In fact, I read data byte by byte and I figured out that some bytes did not show the real values which were saved in the database. I found out what the problem is, but I couldn’t find a solution yet.
I found out that in the web service every varbinary
data is saved to database as byte data (in .Net each byte takes 0 to 255). But, when I want to read the binary data in Java, it takes different values and cause an exception with some values, because in Java a byte value takes -127 to 127.
In my Java application I want to write those data to a file by OutputStream.write(byte[])
method. How can I solve this problem? I think that I have to find a way to convert c# byte[]
to a Java byte[]
(or binary data), but how can I do that?
© Stack Overflow or respective owner