title: check if the file is of a certain type
body: <p>I want to validate if all the files in a directory are of a certain type. What I did so far is.</p>
  
  <pre><code>private static final String[] IMAGE_EXTS = { "jpg", "jpeg" };
  
  private void validateFolderPath(String folderPath, final String[] ext) {
  
          File dir = new File(folderPath);
  
          int totalFiles = dir.listFiles().length;
  
          // Filter the files with JPEG or JPG extensions.
          File[] matchingFiles = dir.listFiles(new FileFilter() {
              public boolean accept(File pathname) {
                  return pathname.getName().endsWith(ext[0])
                          || pathname.getName().endsWith(ext[1]);
              }
          });
  
          // Check if all the files have JPEG or JPG extensions
          // Terminate if validation fails.
          if (matchingFiles.length != totalFiles) {
              System.out.println("All the tiles should be of type " + ext[0]
                      + " or " + ext[1]);
              System.exit(0);
          } else {
              return;
          }
  
      }
  </code></pre>
  
  <p>This works fine if the file name have an extension like {file.jpeg, file.jpg}
  This fails if the files have no extensions {file1  file2}. 
  When I do the following in my terminal I get: </p>
  
  <pre><code>$ file folder/file1 
  folder/file1: JPEG image data, JFIF standard 1.01
  </code></pre>
  
  <p><strong>Update 1:</strong></p>
  
  <p>I tried to get the magic numbers of the file to check if it is JPEG:</p>
  
  <pre><code>for (int i = 0; i &lt; totalFiles; i++) {
              DataInputStream input = new DataInputStream(
                      new BufferedInputStream(new FileInputStream(
                              dir.listFiles()[i])));
  
              if (input.readInt() == 0xffd8ffe0) {
                  isJPEGFlag = true;
              } else {
                  isJPEGFlag = false;
                  try {
                      input.close();
                  } catch (IOException ignore) {
                  }
                  System.out.println("File not JPEG");
                  System.exit(0);
              }
          }
  </code></pre>
  
  <p>I ran into another problem. There are some <strong>.DS_Store</strong> files in my folder. 
  Any idea how to ignore them ? </p>