简体   繁体   English

我无法获取文件路径

[英]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.

相关问题 我无法在Android Nougat中获得根路径usb otg。但是能够获得SD卡的根路径 - I am not able get root path usb otg in Android Nougat .but able to get root path of sd card 我无法通过代码设置要添加到jar中的类文件的路径 - I am not able to set the path of the class file which I am adding in the jar through code 我正在尝试使用Java将MySql数据导出到文件中,但是我无法获取表头 - I am trying to export MySql data to a file using Java, but I am not able to get the table headers 为什么我无法获得javac -version? - Why am I not able to get javac -version? 我无法在我的 Servlet 中获取 cookie - i am not able to get cookie in my Servlet 我无法将所有数据写入文件 - I am not able to write all data to a file 无法获取Android中选择器文件的路径 - Not able to get path of chooser file in android 在Java / Android中,为什么我可以从ParcelFileDescriptor获取整数文件描述符? - In Java / Android, why am I able to get an integer file descriptor from ParcelFileDescriptor? 当我能够通过FileZilla连接时,我无法从SFTP文件源中提取文件 - I am not able to pull files from SFTP file source while I am able to connect through FileZilla Java 创建 excel 文件,但我无法打开该文件 - Java creates excel file but i am not able to open the file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM