I am retrieving an image from the SQL database into Byte() variable in VB.NET.
Dim img as byte() = dr(0)
How do I create a file in my C:\images\ directory from the above img.
I want to read the img and then create a file with name bimage.gif.
Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file. Example: Java.
The Byte data type holds an integer in the range of 0 to 255. Bytes are frequently used to access binary files, image and sound files, and so on. Note that you no longer use bytes to access individual characters. Unicode characters are stored in two bytes.
WriteAllBytes(String) is an inbuilt File class method that is used to create a new file then writes the specified byte array to the file and then closes the file. If the target file already exists, it is overwritten. Syntax: public static void WriteAllBytes (string path, byte[] bytes);
The easiest way is to use File.WriteAllBytes
Dim img as byte()=dr(0)
File.WriteAllBytes("C:/images/whatever.gif", img)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With