It returns the last component in a file path. It takes E.g: d:/tmp/file.txt and returns file.txt
(String path)
| 88 | * It takes E.g: d:/tmp/file.txt and returns file.txt |
| 89 | */ |
| 90 | public static String getLastPathComponent(String path){ |
| 91 | if(path == null || path.length() == 0) return ""; |
| 92 | //we should look both for "/" and "\" as on windows the file separator is"\" |
| 93 | //but a path coming from an URL will be separated by "/" |
| 94 | int index = path.lastIndexOf('/'); |
| 95 | if(index == -1) index = path.lastIndexOf('\\'); |
| 96 | if(index == -1) return path; |
| 97 | else return path.substring(index + 1); |
| 98 | }// getLastPathComponent() |
| 99 | |
| 100 | /** Get a string representing the contents of a text file. */ |
| 101 | public static String getString(String fileName) throws IOException { |
no test coverage detected