で受信したバイトはありません数: 私は実装するコードを以下している:私は、次の作業URL接続からダウンロードされたバイト数を決定したいのjava
.......
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream is = connection.getInputStream(); // throws an IOException
DataInputStream dis = new DataInputStream(new BufferedInputStream(is));
FileOutputStream fos = new FileOutputStream("C:\\Picture.jpeg");
int read =0;
byte[] bytes = new byte[1024];
while((read = dis.read(bytes)) != -1)
{
fos.write(bytes, 0, read);
}
System.out.println(read + " byte(s) copied");
を最後の行からの出力としてあります次のようになります。
Opening connection to http://www.xyz.com//Picture.jpeg...
Copying image resource (type: application/jpeg, modified on: 02/02/2010 4:19:21 AM)...
-1 byte(s) copied
私のコードのエラーは何ですか?私は
それを取得しないでください助けてください。ループの後で 'read'は常に' -1'になります。さもなければ、あなたは無限ループに入ります。具体的な問題は何ですか? – home
このリンクに従ってください。これは問題と同じです。 http://stackoverflow.com/questions/6081796/menu-item-enable-disableあなたの問題を解決するのに役立つこのリンクをご覧ください。 http://www.eclipsezone.com/eclipse/forums/t90781.rhtmlおよびhttp://www.odevelop.com/blog/?p=211 –