Monday, 15 April 2013

java - How to get list of files from URL -



java - How to get list of files from URL -

i have url http ://......../somefolder/ want names of files within folder. have tried below code it's showing error.

url url = new url("http://.............../pages/"); file f=new file(url.getfile()); string list[]=f.list(); for(string x:list) { system.out.println(x); }

error :-exception in thread "main" java.lang.nullpointerexception @ directory.main(directory.java:25)

it's not possible this.

http has no concept of "folder". thing see when open url web page, happens have bunch of links other pages. it's not special in way far http concerned (and hence http clients, 1 built java).

that's not it's impossible. might able file list way.

edit: reason code doesn't work nonsensical. url.getfile() homecoming "/......./pages/", , pass file constructor - gives file representing path /....../pages/ (or c:\......\pages\ on windows). f.list() sees that path doesn't exist on computer, , returns null. there no way file points url, there's no way int value 5.11.

java

No comments:

Post a Comment