Questions tagged [file-not-found]

An error, exit status, or exception that indicates that the file denoted by a specified pathname could not be found.

An error, exit status, or exception that indicates that the file denoted by a specified pathname could not be found. In other words, you're trying to access a file that doesn't exist where the code is expecting it to be.

This could occur as a result of many different actions, such as...

  1. The file doesn't actually exist, or was deleted before you could access it
  2. There is a spelling mistake in your pathname, or the pathname contains characters that aren't permitted in the pathname.
  3. You're using a relative pathname (such as file.txt) and the file doesn't exist in the default working directory for your application
  4. The code is getting confused due to different directory path indicators on different operating systems (ie / vs \)
  5. The programming language interprets the \ character in a String to be a escape character for a special symbol (such as \n indicating new-line), and you're using single \ slashes as directory indicators instead of \\ for a single escaped slash.
  6. In some languages, it could also give this exception if you aren't able to access the file due to security permissions.

Your code should be able to prevent or handle this condition, such as by doing the following...

  1. Detect - Many programming languages allow you to create a File object as a virtual representation of a physical file. Further to this, you can usually call a method or function that asks whether the file exists, such as exists();. This would allow you to check the file exists before you attempt to access it
  2. Prevent - If the user is selecting a file, present them with a FileChooser dialog rather than a text entry field. FileChooser dialogs echo the files that exist in the system, so spelling mistakes are avoided. If you're using relative paths, convert them to absolute paths if practical, or ensure you set the relative path location to a known directory before trying to access files relatively.
  3. Handle - Wrap your file access methods in exception-handling code, such as a try-catch block. This will allow you to catch unexpected exceptions, and perform an alternate operation, such as alerting the user of the error.
601 questions
-1
votes
1 answer

FileReader not working in java and throws FileNotFoundException, although the file is in the same directory

I am trying to open a txt file in a java program and the compiler keeps advice me throwing the error, that is responsible for the program crash: FileNotFoundException I am working on intelliJ and the file is in the same directory I am working on,…
-1
votes
1 answer

Reading in .txt file in Python

I have a txt file with data like this: AL Autauga AL Baldwin AL Barbour AL Bibb def stateToCounties(filename): """ :param filename: text containing state name, tab, county name, enter button... :return: { state name : [list of…
user12369128
-1
votes
1 answer

UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND api.sendgrid.com api.sendgrid.com:443 when sending mail

UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND api.sendgrid.com api.sendgrid.com:443 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26) (node:6768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This…
Varsha
  • 1
  • 1
-1
votes
1 answer

Getting "FileNotFoundError" when opening files

I've written a script to open, read, and then close a text file, but I keep getting an error message saying it can't find the file I specify. I've massively reduced the code but I still get the same error message. The code: txt = open("textf.txt",…
Miles Kent
  • 48
  • 8
-1
votes
1 answer

How does a tcp clients understands the server status codes

I am writing a socket programming in C to transfer files from Server to Client. where client sends a filename to server and the server reply with the file content. I couldn't understand how a server can intimate the client when the file asked by the…
-1
votes
2 answers

file not found: HelloWorld.java

I started to learn Java and the first task was do write a 'Hello World' Code. Saved it in documents and had to open it in cmd. thats what i type in: cd documents javac HelloWorld.java my problem: I always get the error: file not found:…
Erik
  • 3
  • 3
-1
votes
1 answer

Jasper file not found when build with maven, working fine in eclipse

the prob im facing is, when Im running my project in eclipse its able to find my jasper file and showing the report but when im making jar of my project and running it, its not able to find my jasper file and throwing FileNotFoundException.. Path…
Krish
  • 19
  • 1
  • 2
  • 7
-1
votes
1 answer

Js file not found in react-native android project

I want to make a app having splash screen with a login page using react-native- navigation.When i compile the code this error occured error screen
-1
votes
2 answers

JAVA - "no such file or directory" - Scanner

Why is the following code throwing a No Such File Found Exception? The path is correct and the file does really exist. Code: java.util.Scanner s = new java.util.Scanner( new File(getClass().getResource("file.txt").getFile()));
-1
votes
1 answer

How to catch error and stop using IF and ELSE statement?

Hello i am new to python programming. I am self learning by doing a project. the code below is working fine, but i want to catch the exception if the condition is FALSE. i already have a statement to print if the directory is not there; and…
Dean
  • 65
  • 1
  • 8
-1
votes
2 answers

File Not Found Error Python

I'm trying to read a file on a specific path with with open method. Normally I do this with no problem, but right now there is a txt file on a specific path and Python raising FileNotFoundError. I formatted the pc today, I don't know the problem is…
GLHF
  • 3,835
  • 10
  • 38
  • 83
-1
votes
1 answer

C# can't see windows program

I am creating a program that has to work with Windows system programs like a C:\windows\System32\bcdedit.exe. If I try to reach for example mspaint it works good. IO.File.Exists(@"C:\windows\System32\mspaint.exe") // return…
Misaz
  • 3,694
  • 2
  • 26
  • 42
-1
votes
1 answer

Python 3.4 FileNotFoundError: [Ernno 2] No such file or directory but the file IS there

This is my error: However there is a file at 'C:/Python34/Python34/build/exe.win32-3.4/library.zip/pygame/freesansbold.ttf' Look: When I check for the file by swiping in from right on my computer and typing address it also says it doesn't exist.…
Funk Pigeon
  • 168
  • 2
  • 12
-1
votes
1 answer

Java Eclipse - The system cannot find the file specified ( java.io.FileNotFoundException )

In my code, I would like to read input from a file, and I am getting an exception. Exception in thread "main" java.io.FileNotFoundException: TestValues.csv (The system cannot find the file specified) Exception in thread "main"…
user2041390
  • 43
  • 1
  • 3
  • 9
-1
votes
1 answer

GIT conflict in Storyboard and results error as main.storyboard not found

I've tried taking pull from GIT and some conflicts occurred on my Storyboard file. I have resolved all conflicts from a different computer (windows computer) and then replaced new Main.storyboard file with old file (on Mac). Now, when i run my…
Radix
  • 2,527
  • 1
  • 19
  • 43