Skip to content
← Back to Community
How to get a file path?
Profile icon
RyanTenerelli

I have a text file called WaterQuality1.txt in one of my folders and I tried to create a File object in Main by writing "File file1 = new File("WaterQuality1.txt");" but it's giving me a FileNotFoundException. Am I writing the file path wrong? Or something else?

Thanks!

Voters
Profile icon
RyanTenerelli
Comments
hotnewtop
Profile icon
Zavexeon

Language?

Profile icon
RyanTenerelli

@Zavexeon whoops Java. sorry. But I seem to have figured it out.

Profile icon
BobForJob

I am having same issue did you find fix?

Profile icon
RyanTenerelli

@BobForJob Yes. If you have Windows you must hold in SHIFT while right-clicking the file whose path you want to copy. When the options come up select "Copy as path."

At least that's one way of doing it.

Profile icon
[deleted]

@RyanTenerelli That isn't working for me ;-;