What should be the syntax when the excel file that I'm trying to call is imported within the project.
Asked
Active
Viewed 1,606 times
0
-
I guess this is not a duplicate cos that topic shows path on the local file. i need syntax on how to locate the file based on the project specified on the photo attached – Mary Madelynn Cruz May 28 '19 at 08:10
-
Pls don't put just screenshot of your issue/error it's batter to add description of your image too ,as well If those answers do not fully address your question, please ask a new question. – Ajay Pandya Aug 20 '19 at 06:33
2 Answers
0
Use :
public class ReadFileExcel
{
public static void main(String[] args) throws IOException
{
ClassLoader classLoader = new ReadFileExcel.getClass().getClassLoader();
File file = new File(classLoader.getResource("./dashboards.xlsx").getFile());
// replace the below one with the above but just change the name of the class
var file = new FileInputStream("Dashboard.xlsx");
}
}
Note : Build the project, otherwise classloader will not able to read.

Anish B.
- 9,111
- 3
- 21
- 41
-
i'm not sure where part should i change these line of yours on my side. ClassLoader classLoader = new ReadFileExcel.getClass().getClassLoader(); – Mary Madelynn Cruz May 28 '19 at 08:09
-
ClassLoader classLoader = new {class where you are reading thefile}.getClass().getClassLoader(); – Anish B. May 28 '19 at 08:49
0
The syntax you are using is correct but make sure your using the correct path of your local file.
When your local file is in the same package/folder where you write your codes.Just write down its file name.
var file = new FileInputStream("Dashboard.xlsx");
or try using Absolute path of your filename.
var file = new FileInputStream("M3A FrontEndPoc/Dashboard.xlsx");

francis
- 1
- 2