How to paint bytearray
-
Doing a post-requirement to retrieve the application, in return, getting bytearray how to paint it somewhere? If I'm trying to put it in a textview, I'm getting a crash.
String myURL = "http://s92640jz.bget.ru/register.php"; String params = "login=user123&open_key=rgh24sfs3efs234dir&key_size=4096"; byte[] data = null; InputStream is = null;
try { URL url = new URL(myURL); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Content-Length", "" + Integer.toString(params.getBytes().length)); OutputStream os = conn.getOutputStream(); data = params.getBytes("UTF-8"); os.write(data); data = null; conn.connect(); int responseCode= conn.getResponseCode(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); is = conn.getInputStream(); byte[] buffer = new byte[1024]; // Такого вот размера буфер // Далее, например, вот так читаем ответ int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { baos.write(buffer, 0, bytesRead); } data = baos.toByteArray(); } catch (Exception e) { } finally { try { if (is != null) is.close(); } catch (Exception ex) {} }
-
Arrays.toString(s) will return
String
presentation of massbyte[] b1 = new byte[] {97, 98, 99};
String s1 = Arrays.toString(b1);
String s2 = new String(b1);Log.v("MYLOG", s1); // -> "[97, 98, 99]"
Log.v("MYLOG", s2); // -> "abc";