[英]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)". 我已经从excel文件中创建了用于读取数据的脚本,但是它给出了像“C:\\ testdata.xls(系统找不到指定的文件)”这样的错误。 Please Hple.
请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.
我想你的文件在C的子目录中。如果它在子目录中,则包含文件的保持路径。 For example, "C:\\Users\\nicky\\Desktop\\MyProgram\\file.txt" (double backslashes)
例如,“C:\\ Users \\ nicky \\ Desktop \\ MyProgram \\ file.txt”(双反斜杠)
Or you could just copy the file into your project folder and call it by its name. 或者您可以将文件复制到项目文件夹中并按名称调用它。 "file.txt"
“file.txt的”
我的文件路径正确但我的文件扩展名错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.