Android URL to File Name Convert getFileName(URL url)

Here you can find the source of getFileName(URL url)

Description

returns the last element of the URL's path

License

Open Source License

Parameter

Parameter Description
url to parse

Return

the last element of the URL's path

Declaration

public static String getFileName(URL url) 

Method Source Code

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.net.URL;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import net.sf.json.JSON;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;

public class Main{
    /**/*from  ww w.j a v  a 2s.  c  om*/
     * returns the last element of the URL's path
     *
     * @param url to parse
     * @return the last element of the URL's path
     */
    public static String getFileName(URL url) {
        String[] pathElements = url.getPath().split("/");
        return pathElements[pathElements.length - 1];
    }
}

Related

  1. toFile(URL url)