4

I am working on an app and I have to use a certificate and this is the code :

File f = new File("‪‪D:\\john.doe.pfx");

When I run the app it gives me this error :

java.io.FileNotFoundException: ‪‪D:\john.doe.pfx (The filename, directory 
name, or volume label syntax is incorrect)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at testoauth.TestOAUTH.main(TestOAUTH.java:58)

The certificate was in a folder called "proiect oauth" and i got it out and put it directly in D:

I would like to use the file and not give error

  • 5
    Please check, if the file named "`D:\john.doe.pfx`" is there and is accessible by the user. Just copy it in your clipboard, press Windows-R and paste it. It should open, either in editor, keystore-app or dialog which asks what to do with this file. Explorer can mislead you. – SirFartALot May 22 '19 at 12:22
  • @HovercraftFullOfEels I moved the certificate to D: without being in any folders – Serban Ciofliceanu May 22 '19 at 12:22
  • 1
    Hm, show an image of the file explorer – Hovercraft Full Of Eels May 22 '19 at 12:23
  • 1
    Indeed, the simplest answer is that the file is not actually named john.doe.pfx. How silly it may sound. It might be something you don't actually see, like there being a space in the filename. – Gimby May 22 '19 at 12:27
  • 3
    The string you are using has invisible unicode characters in it. ```new File("\u202a\u202aD:\\john.doe.pfx");```. Remove those invisible characters at the start. – khelwood May 22 '19 at 12:32
  • Note that when a file does not exist, the exception thrown is `java.nio.file.NoSuchFileException: D:\john.doe.pfx` (with nothing afterwards). Here it explicitly says `syntax is incorrect`. – Jaroslaw Pawlak May 22 '19 at 12:43
  • Possible duplicate of [File.isFile() returns incorrect result?](https://stackoverflow.com/questions/51627022/file-isfile-returns-incorrect-result) – SirFartALot May 22 '19 at 12:54

1 Answers1

13

The string you are using has invisible unicode characters \u202a at the start.

It is as if you had:

new File("\u202a\u202aD:\\john.doe.pfx");

which is not the correct path.

Retype the line and omit the invisible characters at the start.

khelwood
  • 55,782
  • 14
  • 81
  • 108