InputStream in= getUrlSource(map);
int read;
ByteArrayOutputStream byteArray= new ByteArrayOutputStream();
while ((read = in.read()) != -1)
{
byteArray.write(read);
byteArray.flush();
}
byte[] bt = byteArray.toByteArray();
int read;
ByteArrayOutputStream byteArray= new ByteArrayOutputStream();
while ((read = in.read()) != -1)
{
byteArray.write(read);
byteArray.flush();
}
byte[] bt = byteArray.toByteArray();
比如 1k大小
InputStream in= getUrlSource(map);
byte buffer=new byte[1024];
int read;
ByteArrayOutputStream byteArray= new ByteArrayOutputStream();
while ((read = in.read(buffer))>0)
{
byteArray.write(buffer,0,read);
byteArray.flush();
}
byte[] bt = byteArray.toByteArray();
read = in.read(buffer)
如果我读进来的buffer没有达到1024b,那我程序一直在等到有1024b才结果,请问有没有什么方法可以解决这个问题?
public abstract int read()
throws IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.
Returns:
the next byte of data, or -1 if the end of the stream is reached.
应该不会出现你说的问题呀