user2696466
user2696466

Reputation: 740

file not found exception from FileReader

sorry for this dumb question. but i am really not able to find where i am doing wrong. please help. i am trying to parse a file using JSON. file is there in the system too. but it is showing filenotfound exception. and its really frustrating.

snippet of my code is below :

        System.out.println("Please provide JSON file path : ");
        filePathJson = "\"D:\\files\\test.xlsx\"";
                //in.nextLine();

        System.out.println("Please provide Excel file path : ");
        filePathExcel = in.nextLine();

        Object obj = parser.parse(new FileReader(filePathJson));
        System.out.println("hii");

        JSONArray array = new JSONArray();

and error I am getting :

Please provide JSON file path : 
Please provide Excel file path : 
"D:\\files\\test1.xlsx"
java.io.FileNotFoundException: "D:\files\test.xlsx" (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:137)
    at java.io.FileInputStream.<init>(FileInputStream.java:96)
    at java.io.FileReader.<init>(FileReader.java:58)
    at JavaJsonSplitter.main(JavaJsonSplitter.java:50)

Can somebody point me where i am doing wrong.

please ignore one useless sysout.

Upvotes: 0

Views: 3241

Answers (5)

Balaji Dhanasekar
Balaji Dhanasekar

Reputation: 1080

The clue is here

java.io.FileNotFoundException: "D:\files\test.xlsx" (The filename, directory name, or volume label syntax is incorrect)

Try this

filePathJson = "D:\\files\\test.xlsx";

Upvotes: 0

Appoorva Faldu
Appoorva Faldu

Reputation: 444

@user2696466 -

please see the revise code see if it works

System.out.println("Please provide JSON file path : ");
    **filePathJson = "D:/files/test.xlsx/"**
            //in.nextLine();

    System.out.println("Please provide Excel file path : ");
    filePathExcel = in.nextLine();

    Object obj = parser.parse(new FileReader(filePathJson));
    System.out.println("hii");

    JSONArray array = new JSONArray();

Upvotes: 0

Ketan Bhavsar
Ketan Bhavsar

Reputation: 5396

filePathJson = "\"D:\\files\\test.xlsx\"";

Should be like

filePathJson = "D:\\files\\test.xlsx";

Upvotes: 2

Rahul
Rahul

Reputation: 45060

Remove the extra double quotes surrounding the file path. That is not required at all.

filePathJson = "D:\\files\\test.xlsx";

Upvotes: 2

T.J. Crowder
T.J. Crowder

Reputation: 1074238

You're actually putting quotes in the filename. Remove them, you would only need actual quotes around it on the command line and such. When you're giving a filename to FileReader (or any other method that expects a filename, not a command line), you just give the filename (even if it has spaces in it).

E.g.,

filePathJson = "\"D:\\files\\test.xlsx\"";

becomes

filePathJson = "D:\\files\\test.xlsx";

Upvotes: 4

Related Questions