eclipse作为客户端,myeclipse作为服务器,服务器上有一张图片,我想在eclipse上进行下载图片保存到本地,但是出现了问题

下面是我的eclipse上的代码:
public class HttpUtils {
private static String URL_PATH="http://localhost:8080/myhttp/zxc.jpg";
//private static String URL_PATH="http://img4.duitang.com/uploads/item/201204/26/20120426103030_2hnVC.jpeg";
public HttpUtils () {
}
public static void saveImageToDisk() {
InputStream inputStream=getImageStream();
FileOutputStream fileOutputStream=null;
byte[] data=new byte[1024];
int len=0;
try {
while ((len=inputStream.read(data))!=-1) {
fileOutputStream = new FileOutputStream("D:\\Test.jpg");
fileOutputStream.write(data,0,len);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(fileOutputStream!=null){
try {
fileOutputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(inputStream!=null){
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static InputStream getImageStream() {
InputStream inputStream=null;
HttpURLConnection urlConnection=null;
try {
URL url=new URL(URL_PATH);
if(url!=null){
urlConnection = (HttpURLConnection)url.openConnection();
urlConnection.setConnectTimeout(3000);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod("GET");
int responseCode=urlConnection.getResponseCode();
if(responseCode==200){
inputStream = urlConnection.getInputStream();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return inputStream;
}
public static void main(String[] args) {
saveImageToDisk();
}
}
为什么出现这个问题,就算把PATH改成网上的图片地址也是这种情况,请大神解决!
------解决思路----------------------
while ((len=inputStream.read(data))!=-1) {
fileOutputStream = new FileOutputStream("D:\\Test.jpg");
fileOutputStream.write(data,0,len);
}
fileOutputStream的实例化放到while循环外面。。我没这么写过,猜测。。你可以debug看看