AM пытается загрузить файл из сети, используя класс url & urlconnection в java, используя этот код.
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(destination);
} catch (FileNotFoundException ex) {
}
try {
URL url = null;
try {
url = new URL("here is the url");
//
} catch (MalformedURLException ex) {
ex.printStackTrace();
}
URLConnection urlc = null;
try {
urlc = url.openConnection();
System.out.println("Conneceted");
} catch (IOException ex) {
ex.printStackTrace();
}
try {
bis = new BufferedInputStream(urlc.getInputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
bos = new BufferedOutputStream(fos);
// System.out.println("absolute path="+destination.getAbsolutePath());
int i;
try {
while ((i = bis.read()) != -1) {
System.out.print((char) i);
bos.write(i);
}
JOptionPane.showMessageDialog(this, "downloadeded sucessfully");
this.dispose();
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, "could not be diownloaded \n please try again");
ex.printStackTrace();
}
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Когда я запускаю этот код в моей системе Windows, он работает отлично, но когда я берукод для Mac OS это дает мне исключение
Exception in thread "Thread-2" java.lang.NullPointerException
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at java.io.FilterOutputStream.close(FilterOutputStream.java:140)
at FileDownloader.Download(FileDownloader.java:201)
at FileDownloader$2.run(FileDownloader.java:114)
at java.lang.Thread.run(Thread.java:637)
Может кто-нибудь сказать мне, в чем может быть причина?и как я могу решить это?
Заранее спасибо