You can try this
File file=new File("resources/upload/pdf/APPLE ははは.pdf");
System.out.println(file.getPath().replaceAll(file.getName(),""));
Out put:
resources/upload/pdf/
Question
I have a fileUrl
given to me by my server resources/upload/pdf/APPLE ははは.pdf
.
My problem is how to get resources/upload/pdf/
since I can take the last path of the url which is APPLE ははは.pdf
by using this code:
public static String getLastPathFromUrl(String url) {
return url.replaceFirst(".*/([^/?]+).*", "$1");
}
Solution
You can try this
File file=new File("resources/upload/pdf/APPLE ははは.pdf");
System.out.println(file.getPath().replaceAll(file.getName(),""));
Out put:
resources/upload/pdf/