我正在制作一个程序来将excel文件中的数据存储在数据库中。我希望用户在控制台中提供文件的完整路径,并在程序之后只使用文件名继续。
加载完整路径的代码是:
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('.')));
之后我想拥有:String filename = .......
用户输入的完整路径如下:C:\\Users\\myfiles\\Documents\\test9.xls
我将创建的文件名将仅采用不带.xls
! 谁能帮助我如何做到这一点?
如果我想作为文件名“test9.xls”,我会怎么做?——</p>