Questions tagged [filenotfoundexception]

A Java or Android exception that indicates that the file denoted by a specified pathname could not be opened.

This exception is part of the old Java file API. Newer code in Java (note: NOT Android) should use JSR 203 instead (i.e. Paths, Files). JSR 203 (known as NIO.2) has its own java.nio.file.NoSuchFileException, see also .

One problem with this exception is that despite its name, it doesn't always mean that the filesystem object at the given path is actually missing. Here are a few possibilities where this exception can be thrown with a cause other than the file missing:

  • permission denied: an attempt is made to open the file in write mode but the process only has read only access; or the file is in a directory the contents of which the application cannot access;
  • read only filesystem: an attempt is made to open the file in write mode, the process has write access to the file but the underlying filesystem is read only;
  • symbolic link loop: the denoted path is a symbolic link which loops on itself.
1712 questions
122
votes
8 answers

FileNotFoundException while getting the InputStream object from HttpURLConnection

I am trying to send a post request to a url using HttpURLConnection (for using cUrl in java). The content of the request is xml and at the end point, the application processes the xml and stores a record to the database and then sends back a…
naiquevin
  • 7,588
  • 12
  • 53
  • 62
94
votes
22 answers

open failed: EACCES (Permission denied)

I am having a very weird problem with storage accessing on some devices. The app works on my testing devices (Nexus 4 & 7, Samsung GS5). All my devices running Android 4.4.2. But I received many emails from users saying that the app can not write to…
user3613696
  • 973
  • 1
  • 7
  • 9
76
votes
8 answers

java.io.FileNotFoundException: the system cannot find the file specified

I have a file named "word.txt". It is in the same directory as my java file. But when I try to access it in the following code this file not found error occurs: Exception in thread "main" java.io.FileNotFoundException: word.txt (The system cannot…
name123
  • 773
  • 3
  • 9
  • 9
61
votes
12 answers

Java says FileNotFoundException but file exists

I have an assignment for my CS class where it says to read a file with several test scores and asks me to sum and average them. While summing and averaging is easy, I am having problems with the file reading. The instructor said to use this…
scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
58
votes
14 answers

java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

i am programming a soundboard from android. the problem is that some sounds works, and some dont work. here is the traceback that i get for the sounds that doesnt work 05-31 13:23:04.227 18440 18603 W System.err: java.io.FileNotFoundException: This…
ihucos
  • 1,821
  • 3
  • 19
  • 30
57
votes
5 answers

Java - Access is denied java.io.FileNotFoundException

I have the following code: List items = uploadHandler.parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { File file = new File("D:/Data"); } } When I am trying to save a file, I am getting the…
Jacob
  • 14,463
  • 65
  • 207
  • 320
54
votes
6 answers

java.io.FileNotFoundException: (Access is denied)

I am trying to read the files inside a folder, but when I run the program it throws this exception. I tried with some other folders also. It throws the same exception. Exception in thread "main" java.io.FileNotFoundException: C:\backup (Access is…
John
  • 2,682
  • 5
  • 23
  • 24
54
votes
2 answers

Java Files.write NoSuchFileException

I'm trying to write some text to a file using Files.write() method. byte[] contents = project.getCode().getBytes(StandardCharsets.UTF_8); try { Files.write(project.getFilePath(), contents, StandardOpenOption.CREATE); } catch (IOException ex)…
ioreskovic
  • 5,531
  • 5
  • 39
  • 70
49
votes
2 answers

Java applet can't open files under Safari 7 (Mac OS X 10.9)

We have a web app that uses Java applet to manipulate files on local disk. We develop it for quite a while and we already know all types with issues an applet may have with modern OS'es and browsers and latest Java versions and new security…
JetLizard
  • 639
  • 1
  • 5
  • 8
49
votes
4 answers

Python's "open()" throws different errors for "file not found" - how to handle both exceptions?

I have a script where a user is prompted to type a filename (of a file that is to be opened), and if the file doesn't exist in the current directory, the user is prompted again. Here is the short version: file = input("Type filename: ") ... try: …
user2015601
48
votes
10 answers

How to check if file exists in a Windows Store App?

Is there any other way of checking whether a file exists in a Windows Store app? try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.xml"); //no exception means file exists } catch (FileNotFoundException ex) { …
48
votes
3 answers

HttpURLConnection java.io.FileNotFoundException

The code below works great if I connect to what seems to be Apache servers, however when I try to connect to my .Net server it throws an error. I am guessing it is a header requirement, but I can not seem to get a successful response no matter what…
nathan
  • 477
  • 1
  • 4
  • 8
45
votes
4 answers

FileNotFoundException for HttpURLConnection in Ice Cream Sandwich

I have an Android app that works fine with Android 2.x and 3.x, but it fails when run on Android 4.x. The problem is in this section of code: URL url = new URL("http://blahblah.blah/somedata.xml"); HttpURLConnection urlConnection =…
Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302
34
votes
3 answers

System.DirectoryServices.AccountManagement.PrincipalContext broken after Windows 10 update

I've been using this little function without any issue for the past few years to validate user credentials. The createPrincipalContext method returns a PrincipalContext with ContextType.Machine and the machine name. public static bool…
Nkosi
  • 235,767
  • 35
  • 427
  • 472
29
votes
3 answers

FileInputStream doesn't work with the relative path

I tried to create an object from FileInputStream and pass the relative value of a file to its constructor, but it doesn't work properly and threw a FileNotFoundException try { InputStream is = new FileInputStream("/files/somefile.txt"); } catch…
Mahmoud Elshamy
  • 578
  • 1
  • 5
  • 13
1
2 3
99 100