"代码1" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/d02a785fe6caf6b9d4e602d07803ef50.png)"代码2" (https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241003/248c096b067047ea8b42ec6282977890.png) 为什么我用代码2来下载word或者ppt结果打开就是乱码txt文件就没这种问题,用代码1的都是正常的
小弟对io流很陌生,请问大佬下面的代码怎么优化?图片5Mb的时候要等8sm,怎么提高加载速度? try { URL url = new URL(imageUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); BufferedInputStream bis = new BufferedInputStream(connection.getInputStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = bis.read(buffer)) != -1) { baos.write(buffer, 0, len); } OutputStream outputStream = response.getOutputStream(); response.setContentType("image/jpg"); outputStream.write(baos.toByteArray()); outputStream.flush(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); }