Reputation: 135
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();
Upvotes: 3
Views: 167
Reputation: 714
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.
Upvotes: 1
Reputation: 41
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"
Upvotes: 0