小编ded*_*mar的帖子

从完整路径获取无扩展名的文件名

我正在制作一个程序来存储数据库中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('.')));
Run Code Online (Sandbox Code Playgroud)

之后我想: String filename = .......

用户键入的完整路径如下所示: C:\\Users\\myfiles\\Documents\\test9.xls

我创建的文件名将只使用没有的名称.xls!任何人都可以帮助我如何做到这一点?

如果我想把文件名称作为"test9.xls",我会怎么做? -

java filenames

22
推荐指数
4
解决办法
8万
查看次数

如何处理excel文件中的空白单元格java

我正在制作一个程序,我从excel文件中读取数据并将它们存储在表中.我使用Apache POI制作了程序并且工作正常.但是当文件中有空白单元格时在此输入图像描述我有一些问题.程序跳过空白并读取下一个数据.任何人都可以帮助我如何做到这一点?我知道这个问题有几个帖子,但我没有找到对我有用的东西.

从excel文件中读取数据的代码如下.如您所见,我有3种类型的数据.我将如何为BLANK CELL提供选项?

// Create an ArrayList to store the data read from excel sheet.
        List sheetData = new ArrayList();
        FileInputStream fis = null;
        try {
            // Create a FileInputStream that will be use to read the
            // excel file.
            fis = new FileInputStream(strfullPath);
            // Create an excel workbook from the file system
            HSSFWorkbook workbook = new HSSFWorkbook(fis);

            // Get the first sheet on the workbook.
            HSSFSheet sheet = workbook.getSheetAt(0);

            // store the data read on an ArrayList …
Run Code Online (Sandbox Code Playgroud)

java apache-poi

3
推荐指数
1
解决办法
4万
查看次数

标签 统计

java ×2

apache-poi ×1

filenames ×1