0

To get HTTP links with direct link to file (with NAME and EXTENSION) like http://website.com/file.avi could be done with

URL FileLocation = new URL("string");
String Name = FileLocation.getFile();

which would return NAME with EXTENSION (/filename.ext)

but How to get Filename for URLs with php ID like

http:///website.com/download.php?d=9594

I want to do this in JAVA only.

rohitpal
  • 455
  • 1
  • 6
  • 21

2 Answers2

0

You want to look for Content-Disposition field in the header of HTTP response, e.g.

Content-Disposition: attachment; filename="fname.ext"

Since it is in the HTTP header, you will need to start downloading the message first before getting the file name. Here is an example of how you use URLConnection and how to get a header field

gigadot
  • 8,879
  • 7
  • 35
  • 51
0
 File file=new File("C:/work/chandan/deepak.txt");
  URL url=null;
 ....
 ....

url=file.toURL(); //file:/C:/work/chandan/deepak.txt
System.out.println("The url is" + url);
Raj Adroit
  • 3,828
  • 5
  • 31
  • 44