Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read uploaded file name in java

I have uploaded a file in java, and I am trying something like this to get the uploaded file name

private UploadedFile uploadedFile;
System.out.println("File name: " + uploadedFile.getName());

and it is printing the filename along with its path relative to Computer as:

File name: E:\Grievances Project\Feb 2012 data\22439-29-02-2012\22439-29-02-2012.xls

how can i get only the uploaded file name irrespective of the place from where it is being uploaded like :

File name: 22439-29-02-2012.xls
like image 710
abhi Avatar asked Sep 01 '26 21:09

abhi


1 Answers

System.out.println(new File(
    uploadedFile.getName()).getName());

You might also look through the String methods for things like lastIndexOf("path separator") and substring(int,int), to handle it in a more generic way.

like image 179
Andrew Thompson Avatar answered Sep 03 '26 12:09

Andrew Thompson