Forum posts for reader

InputStream reader

I'm currently trying to read in a image file from the server but either getting a incomplete data or

Exception in thread 'main'
java.lang.NegativeArraySizeException.


Has this something to do with the buffer size? I have tried to use static size instead of contentlength. Please kindly advise.

URL myURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection)myURL.openConnection();
connection.setRequestMethod('GET');
status = connection.getResponseCode();

if (status == 200)
{
int size = connection.getContentLength() + 1024;
byte[] bytes = new byte[size];
InputStream input = new ByteArrayInputStream(bytes);
FileOutputStream out = new FileOutputStream(file);
input = connection.getInputStream();

int data = input.read(bytes);
while(data != -1){
out.write(bytes);
data = input.read(bytes);
}
out.close();
input.close();

View complete forum thread with replies

Other posts related to reader

See Related Forum Messages: Follow the Links Below to View Complete Thread

fingerprint reader or thumb reader
adobe reader and acrobat reader [closed]
reader vs buffered reader
CSV parser/reader for C#? [closed]
The “reader” monad
Fingerprint Reader
Blackberry smartcard reader example
Casting to a reader or creating a new reader
Fingerprint Reader
PDF Reader
fingerprint reader [closed]
InputStream reader
Buffered Reader
geotools reader
File reader encapsulation in a table reader

What is the carbon footprint of your coffee?

Is it low? Is it high? Can this things really kill the planet Earth? Maybe the answer will surprise you. Maybe not.