0

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
user2696466
  • 650
  • 1
  • 14
  • 33

5 Answers5

4

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";
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
2

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

filePathJson = "D:\\files\\test.xlsx";
Rahul
  • 44,383
  • 11
  • 84
  • 103
2
filePathJson = "\"D:\\files\\test.xlsx\"";

Should be like

filePathJson = "D:\\files\\test.xlsx";
Ketan Bhavsar
  • 5,338
  • 9
  • 38
  • 69
0

@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();
Appoorva Faldu
  • 344
  • 4
  • 17
  • For a useful answer, always say **what** you've changed and **why**. (And don't introduce syntax errors for emphasis.) – T.J. Crowder Sep 24 '13 at 12:37
0

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";
Balaji Dhanasekar
  • 1,066
  • 8
  • 18