我正在製作一個程序來存儲數據庫中的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」? -
變化 '/' 到 '\\' *字符串文件= strfullPath.substring (strfullPath.lastIndexOf('\\')+ 1); * – 2013-04-29 08:04:58
如果我想把它作爲文件名「test9.xls」,我該怎麼做? – dedmar 2013-04-29 08:15:27