Here you can find the source of getName(URI uri)
Parameter | Description |
---|---|
uri | whose path to get name of. |
public static String getName(URI uri)
//package com.java2s; import java.io.File; import java.net.URI; public class Main { /**/*from w ww . jav a 2 s .c o m*/ * Derives name from uri. If the uri is local, this is done through the File * interface; else calls getURIName. * * @param uri * whose path to get name of. * @return name of file or directory. */ public static String getName(URI uri) { if (uri == null) return null; if ("file".equals(uri.getScheme())) return new File(uri).getName(); return getURIName(uri); } /** * Path is parsed using '/' as separator. * * @param forwardSlashPath * whose path to get name of. * @return name of file or directory. */ public static String getURIName(String forwardSlashPath) { if (forwardSlashPath == null) return null; int end = forwardSlashPath.length(); if (end == 0) return ""; if (forwardSlashPath.charAt(end - 1) == '/') end = end - 1; if (end == 0) return "/"; int index = forwardSlashPath.substring(0, end).lastIndexOf('/'); return forwardSlashPath.substring(index + 1, end); } /** * Derives name from uri; calls overloaded method. the uri path is parsed * using '/' as separator. * * @param uri * whose path to get name of. * @return name of file or directory. */ public static String getURIName(URI uri) { if (uri == null) return null; return getURIName(uri.getPath()); } }