简体   繁体   中英

I am not able to get the file path

I have created Script for Read data from excel file, but it gives me error like "C:\\testdata.xls (The system cannot find the file specified)". Please Hple. This is my code.

 FileInputStream file = new FileInputStream(new File ("C:\\testdata.xls")); 
 HSSFWorkbook workbook = new HSSFWorkbook(file);
 HSSFSheet sheet = workbook.getSheetAt(0);
 String heading = sheet.getRow(0).getCell(0).getStringCellValue();
 String searchText1 = sheet.getRow(1).getCell(0).getStringCellValue();
 String searchText2 = sheet.getRow(2).getCell(0).getStringCellValue();
 System.out.println("Heading is:" + heading);
 System.out.println("Search Text 1 is:" + searchText1);
 System.out.println("Search Text 2 is:" + searchText2);
 file.close();

You can verify if the path is correct or not by creating file as

new File ("C:\\\\testdata.xls")

Then print the absolute path. Check if it is a valid path.

You probably have to be more specific. I'd imagine your file is in a subdirectory of C. If it is in a subdirectory include the hold path to the file. For example, "C:\\Users\\nicky\\Desktop\\MyProgram\\file.txt" (double backslashes)

Or you could just copy the file into your project folder and call it by its name. "file.txt"

我的文件路径正确但我的文件扩展名错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM