I am making a program to store data from excel files in database. I would like the user to give in console the full path of the file and after the program to take only the file name to continue.
The code for loading the full path is:
String strfullPath = "";
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter the fullpath of the file");
strfullPath = scanner.nextLine();
String file = strfullPath.substring(strfullPath.lastIndexOf('/') + 1);
System.out.println(file.substring(0, file.indexOf('.')));
After that I would like to have: String filename = .......
The full path that the user would type would be like this: C:\\Users\\myfiles\\Documents\\test9.xls
The filename that I would create would take only the name without the .xls
!
Could anyone help me how I would do this?
How i would do it if i would like to take as filename "test9.xls" ? –
I usually use this solution described in other post:
import org.apache.commons.io.FilenameUtils;
String basename = FilenameUtils.getBaseName(fileName);