public class Socket {
public Socket() {
try {
URL url = new URL("http://images2.layoutsparks.com/1/56178/castle-stone-window-grey.jpg");
InputStream in = url.openStream();
BufferedInputStream bin = new BufferedInputStream(in);
ByteArrayOutputStream bout = new ByteArrayOutputStream(4096);
byte[] okunan = new byte[4096];
while(in.read()!= -1){
bout.write(okunan, 0, in.read());
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我收到此错误:java.io.ByteArrayOutputStream.write 处的线程“main”java.lang.IndexOutOfBoundsException 中的异常(未知来源)
我想在写入文件后将此 jpeg 文件读取到 bytearrayoutputstream 中。
对不起我的英语不好..