我正在制作一个程序,用于将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”,应该怎么做? -