How do I pass the file directory and name of file to the PNG class to validate that the file is indeed a png
<p>This is main where I select the file from a JFileDialog. I want to pass the filename and directory to the PNG class to check whether the file is a png or not. But I am stuck again help.</p>

<pre><code>package file;    

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.DefaultCaret;

import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;

public class Driver {


    public static void main(String[] args) throws Exception{


        Files png = new PNG();//create an object of the class png in the parent class Files
        PNG Png = new PNG();//create an object of teh PNg class

        FileDialog FileWindow = new FileDialog(new Frame());//File dialog widnow
        FileWindow.setVisible(true);

        if (FileWindow.getFile() != null) {

            File FileDirectory = new File(FileWindow.getDirectory());//store the directory cheosen by user
            String[] Directory = FileDirectory.list();//creates an array of the directory

            for (int i = 0; i &lt; Directory.length; i++) {

                if (Directory[i] != null) {
                    //Loops through the directory to find the file that match the file that the user selected           
                    if (Directory[i].matches(FileWindow.getFile()) || Directory[i].startsWith(FileWindow.getFile())) {


                        //if file is found it is stored in FileExtract           String FileExtract = Directory[i];

                        //This section gets the file extension

                        int dot = FileExtract.lastIndexOf(".");
                        String FileName = FileExtract.substring(0, dot);
                        String FileExtension = FileExtract.toUpperCase().substring(dot + 1);

                        //get the size of the file
                        File FileSize = new File(FileWindow.getDirectory(), FileExtract); 
                        //name and directory of file is passed to the PNG class to be validated
                        Png.isPng(FileDirectory, Directory[i]);                   

                        //prints out the information for that file
                        png.setFileName(FileName);
                        png.setFileType(FileExtension);
                        png.setFileSize(FileSize.length());

                        png.Display();
                        break;
                    }
                }
            }
        }
    }
}
</code></pre>

<p>This is the PNG class I want to pass teh file name and directory here to confirm that the  file selected in the Jfilechooser is indeed a png file using the magic numbers.</p>

<pre><code>package file;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

public class PNG extends Files {
    //Magic number or hex value for png file
    private static final int MAGIC[] = new int[] { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; 
    // name of teh file and directory is passed here             
    public void isPng(File dir, String file) throws Exception { 
        String[] listOfFiles = dir.list(); //Store the directory here
        for (int i = 0; i &lt; listOfFiles.length; i++) 
        {

            if (listOfFiles[i] != null) 
            {//Search foor the file the user chose in the drive class
                if(listOfFiles[i].matches(file) || listOfFiles[i].startsWith(file)){

                    //if teh file is found then it orints its name
                    System.out.print(file + "\n");

                    //but what i really want is to open that file an read its magic numbers or hex value to get its extension type.
                    //the commented out area is wat i cant figure and i think the FileInputStream is causing teh problem           
                    /* FileInputStream ins = new FileInputStream(file); 


             try { 
               for(int d = 0; d &lt; MAGIC.length; ++d) { 
                  if(ins.read() != MAGIC[d]) { 
                System.out.print("File is not Png");
                  } 
                  else
                System.out.print("File is Png");
               } 

            } 
            finally { 
              ins.close(); 
            } */
                }
            }
        } 
    }
}
</code></pre>
