-2

I am trying to integrate Firebase with my Java Spring web application what runs on server and it give an error:

Unhandled exception: java.io.FileNotFoundException"

The file is exists in the directory:

FileInputStream serviceAccount = new FileInputStream("C:\Users\My Name\Downloads\Projectname\words.txt"); 

I run a bunch of prints when I just used File where it exists, its readable, the full file path or whatever is the exact same as the file path in the FileInputStream but nothing is working. i cant use a try catch because Firebase doesn't allow it or something. At this point I don't know what to do.

Daniel
  • 2,223
  • 3
  • 9
  • 18

2 Answers2

2

As mentioned in the proposed duplicate, it's likely that your problem is that you need to declare the possible exception by adding throws FileNotFoundException to your method (and all methods that call it). See Using FileReader causes a compiler error "unhandled exception type FileNotFoundException"

The code that you posted above also gives an error illegal escape character at compile time (because backslash is used in Java for representing special characters such as newline \n), which seems to be unrelated to the current problem, but you can fix it by replacing each single backslash with two backslashes as follows:

FileInputStream serviceAccount = new FileInputStream("C:\\Users\\My Name\\Downloads\\Projectname\\words.txt");
Flight Odyssey
  • 2,267
  • 18
  • 25
  • As you note, they would have an entirely different compilation error. This answer is wrong. – Sotirios Delimanolis Jan 23 '18 at 02:10
  • If you think it's a duplicate, flag to close as such. – Sotirios Delimanolis Jan 23 '18 at 02:15
  • @SotiriosDelimanolis It's already marked as a duplicate, it was in reading the proposed duplicate that I realized that this might be the OP's issue – Flight Odyssey Jan 23 '18 at 02:16
  • @Daniel Put your new error in a separate question with details of how you added throw, etc. More information will be needed to debug that – Flight Odyssey Jan 23 '18 at 02:17
  • Then your answer is not necessary. The first 2 paragraphs have been demonstrated to be wrong/not relevant and the last is just linking to the duplicate and summarizing what's mentioned there. Please remove it. It makes it harder to delete the question (or have the roomba do it for us). – Sotirios Delimanolis Jan 23 '18 at 02:19
1

When you use path separator, you must remember use \ or / correctly. You should change it to

"C:/Users/My Name/Downloads/Projectname/words.txt"

in Java program.

Vy Do
  • 46,709
  • 59
  • 215
  • 313