Get file name from a file location in Java

new File(fileName).getName();

or

int idx = fileName.replaceAll("\\\\", "https://stackoverflow.com/").lastIndexOf("https://stackoverflow.com/");
return idx >= 0 ? fileName.substring(idx + 1) : fileName;

Notice that the first solution is system dependent. It only takes the system’s path separator character into account. So if your code runs on a Unix system and receives a Windows path, it won’t work. This is the case when processing file uploads being sent by Internet Explorer.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)