I am playing a bit with the new Java 7 IO features, actually I trying to receive all the xml files of a folder. But this throws an exception when the folder does not exist, how can I check if the folder exists with the new IO?

I wonder why you would want to check whether the folder exists. Just because the folder exists when you checked does not mean the folder exists when you create the DirectoryStream, let alone when you iterate over the folder entries.
– OswaldMar 22 '13 at 13:30

correct answer, but a small notice: if(f.isDirectory()) {...} would be enough, as it checks also existence.
– G. DemeckiJan 21 '15 at 11:33

3

This does not answer the OP's question. java.io.file is not part of "new Java 7 IO features" the OP is referring to. The java.nio.file package, which was introduced in Java 7, offers the Paths and Files classes. Other answers here correctly explain how to use these newer classes to solve the OPs problem.
– Doron GoldMar 2 '17 at 22:27

import java.io.*;
public class fileCheck
{
public static void main(String arg[])
{
File f = new File("C:/AMD");
if (f.exists() && f.isDirectory()) {
System.out.println("Exists");
//if the file is present then it will show the msg
}
else{
System.out.println("NOT Exists");
//if the file is Not present then it will show the msg
}
}
}