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

saving into a file in c

the scope of this function is to get inputs and save into a file . simple right ? but i cannot find the file after i input whith the console . please help me ! void addpassenger() { int size = sizeof(struct passenger); struct passenger…
-1
votes
1 answer

CreateProcess with a custom string

I'm trying to run 'CreateProcess' in c, with a custom string that I build. When I'm using a simple string like: TCHAR command[]= _T("MyApp.exe -OPTION1 -OPTION2") Everything seems to work fine. But as I try to build a custom string (with getting…
Isaac
  • 29
  • 6
-2
votes
2 answers

Ubuntu - issue with opening a .txt file from terminal

I have built a .cpp program in order to write some content to a .txt file created within the .cpp file. I manage to write the desired content, however, when I am trying to open the created file from terminal, it says that it cannot find it although…
Simon
  • 4,999
  • 21
  • 69
  • 97
-2
votes
3 answers

No such file or directory - Exception in thread "main" java.io.FileNotFoundException

I am doing a program which reads data from a text file in my macbook and then print asterisks. The problem is that Eclipse can't even find the text file. I checked the file directory multiple times to see if it is right. I just don't know why I am…
-2
votes
2 answers

How to continue loop while checking if file exists using function in python

I'm trying to create a code that will use a function to check if the file exists and if not then it will ask the user for a file name again. This loop should continue until an existing file name is given. I managed to do the same concept using a…
bebarrentine
  • 13
  • 1
  • 4
-2
votes
1 answer

FileNotFoundError Python Script

I am trying to run a python script, .py in the windows command prompt. I drag the script from my files into the command prompt window. I run it. Then, the script presents a prompt for me to enter the file I would like to parse. I am supposed to…
-2
votes
1 answer

My web server cannot find sub directories

Ok, sorry about first question which was a bad question. Second try. I created a web server (or a responder?) using C# and System.Net libraries. Here is server public variables: #region "Variables" private TcpListener _TcpListener; private…
Yahya Gedik
  • 97
  • 1
  • 12
-2
votes
1 answer

javaScript alert and prompt boxes redirect me to another page that says "file not found"

Programming a simple web page but when i use JavaScript alert and prompt boxes I am randomly directed to another screen that says "file not found" This happens when I use the enter key to say "ok"on the Java Script prompt box and anytime I just…
-3
votes
2 answers

gnuplot errors: " line 114: warning: Skipping data file with no valid points", " line 114: all points y value undefined!". "Cannot find or open file"

Here's the image of my data file: EPAM_2000_160.txt When I run it through the cmd prompt, it gives an error: "Cannot find or open file "EPAM_2000_160.txt", No data in plot". Both these files are present in the same folder in documents. I can't…
chimz
  • 1
-3
votes
1 answer

Python: FileNotFoundError: [Errno 2] No such file or directory error

Want to name a file with open function, but error occur. Can not figure out what is the problem, with just img_name = 'image1' everything is OK. Thanks img_name = f'{id_}/image-{img_num}.jpg' with open(img_name, 'wb') as img_file:
Arthur
  • 109
  • 8
-3
votes
1 answer

Various errors in Python Flask

I recently made a code that works just like an Apache server without any index.html The problem is that my code is really buggy, I get different errors (that's why I didn't write them in the title) Down here there is a photo of my work A photo of…
user321985
  • 41
  • 8
-3
votes
2 answers

Why do I keep getting a "java.io.FileNotFoundException" error on my code?

I have been working for a few hours on trying to fix this code, and have visited countless questions on this site. I apologize for the code dump, but I am not sure what is going wrong with the code. The error is based in the reading of the file, but…
Royce T
  • 11
  • 3
-3
votes
1 answer

Plugins cannot find their css styles in folder

I've downloaded this template: http://themeforest.net/item/-medic-medical-health-and-hospital-html5-theme/8331329 from themeforest. Original template has /plugins/ folder in root folder. I moved this folder into /assets/plugins/ and included it in…
Tomas Turan
  • 1,195
  • 3
  • 17
  • 27
-4
votes
1 answer

SSH opening file error - no idea why

Running Debian Linux - newest version. cp /included/filename /usr/bin/ It gives me error "cannot stat '/included/filename': No such file or directory I don't get why there should be an error. I am doing it as superuser.
J. Doe
  • 20
  • 7
-5
votes
2 answers

What is [Errno 2] in pip installation?

I am setting up pip using the official documentation on an Ubuntu 22.04 LTS system, and when I execute the python get-pip.py command, I get an error message stating: python3: can't open file '/home/usr/get-pip.py': [Errno 2] No such file or…
1 2 3
40
41