Convert InputStream to byte array in Java

You can use Apache Commons IO to handle this and similar tasks. The IOUtils type has a static method to read an InputStream and return a byte[]. InputStream is; byte[] bytes = IOUtils.toByteArray(is); Internally this creates a ByteArrayOutputStream and copies the bytes to the output, then calls toByteArray(). It handles large files by copying the … Read more

Creating a byte array from a stream

It really depends on whether or not you can trust s.Length. For many streams, you just don’t know how much data there will be. In such cases – and before .NET 4 – I’d use code like this: public static byte[] ReadFully(Stream input) { byte[] buffer = new byte[16*1024]; using (MemoryStream ms = new MemoryStream()) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)