0

I want to download one file from a URL using Matlab.

According to this: http://www.mathworks.com/matlabcentral/newsreader/view_thread/294528. all works fine until i go to the line:

is = jurl.openStream; 

This gave one error says Java exception occurred: java.lang.NullPointerException.

Edit:

Company='Abc'; 
Depar='Fin'; 
url1='com/';; 
url2='/download_h5_Depar='; 
url3='.h5' ; 
url=strcat(url1,Company,url2,Depar,url3); 
links=url; 

% copy files to local folder 
[pathstr, name, ext ] = fileparts(links);
% name changed here 
name=strcat(Company,'-',Depar);

Error message:

at com.mathworks.net.transport.MWTransportClientPropertiesFactory$1.getPasswordAuthentication(MWTransportClientPropertiesFactory.java:86)
at java.net.Authenticator.requestPasswordAuthentication(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$1.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.privilegedRequestPasswordAuthentication(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getServerAuthentication(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)

Anyone can help? thanks

Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
  • What stream are you trying to open? – Nick Nov 20 '14 at 08:12
  • one url address. it is one file which connects to URL..so I want to open that file and copy the file to my local file .. – user2307344 Nov 20 '14 at 08:15
  • I understand what you want to do... However, I've tried to use the url of this question, and things worked like a charm. So again, what stream are you trying to open? – Nick Nov 20 '14 at 08:22
  • my url is .h5... and the file name is different with the one in the URL. So i defined the downloaded file name, it works, but it stops in this line as mentioned above. – user2307344 Nov 20 '14 at 08:27
  • Please add the code YOU use to the question. – Nick Nov 20 '14 at 08:29
  • This is all what I have editted: Company='Abc'; Depar='Fin'; url1='http://com/'; url2='/download_h5_Depar='; url3='.h5' ; url=strcat(url1,Company,url2,Depar,url3); links=url; % copy files to local folder [pathstr, name, ext ] = fileparts(links); % name changed here name=strcat(Company,'-',Depar); – user2307344 Nov 20 '14 at 08:40
  • Do you understand what I mean...it is difficult to show it clear here... – user2307344 Nov 20 '14 at 08:58
  • Finally..it ended up with the authentication issue ...solved [link](http://stackoverflow.com/questions/1317931/how-do-i-provide-a-username-password-to-access-a-web-resource-using-matlab-urlre) – user2307344 Dec 10 '14 at 07:32

0 Answers0