2 Replies Latest reply: Jan 29, 2009 12:53 PM by 549171 RSS

    Question related to GetFile and GetPath of a URL

    549171
      Hello, i have the following code and i was wondering why GetFile and GetPath shall return the same output,

      e.g. my example here is http://wikis.sun.com/display/SunForums/Tips

      The GetPath returns : Get Path of URL /display/SunForums/Tips
      and the GetFile returns : Get file of URL /display/SunForums/Tips
      the same.
      Well it's just that i would like to use a method which is going to output only the File of a Path, in our example the output should be only Tips.


      CODE :
      import java.io.BufferedReader;
      import java.io.FileNotFoundException;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.net.*;
      
      public class Main {
       
          public static void main(String[] args) throws MalformedURLException, IOException, Exception {
              
                          BufferedReader in = null;
               
                         try {                              //try
              
                                URL yahoo = new URL("http://wikis.sun.com/display/SunForums/Tips");
                               String url_string = yahoo.toString();  // Constructs a string representation of URL
                               URLConnection yc = yahoo.openConnection(); //
                               in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
                               System.out.println("Get file of URL " + yahoo.getFile());                            *//it should return only Tips*
                               System.out.println("Get Path of URL " + yahoo.getPath());
                               } 
       
                                catch (MalformedURLException ex) {
                                                                                    System.err.println("MalformedURLException" + ex);
                                                                                      }
      
                     }
      
               }
      Is there any method which returns only the file of a URL?

      Thanks in advance!