I am trying to read all the files in a folder and for some reason it keeps reading only 1 file over and over again...

private void openFile() throws IOException
	{
		status.setText("Adding Photos");
		File file;
		JFileChooser fileChoose = new JFileChooser(new File("charlie/photo/"));
		int success = fileChoose.showOpenDialog(this);
		if (success == JFileChooser.APPROVE_OPTION) {
			file = fileChoose.getSelectedFile();
			try {
				theList = new PhotoAlbum();
				theList.chooseFile(file, theList);
				itemList.setListData(theList.getArray());
			} catch (NullPointerException e) {
				e.printStackTrace();
			}
		}
		status.append("done\n ");
	}

Is this the part with the problem? Will this just keep sending the same file to my other methods?

or is the problem here in the while loop:

public void readPhotoAlbum(BufferedReader in, PhotoAlbum theAlb, File file) throws IOException, NullPointerException
{
		Photo photo1 = readPhoto(in, file);
		while (photo1 != null){
	theAlb.AddPhoto(photo1);
	System.out.println( "\nYou created the Item:\n\t" + photo1);
	photo1 = readPhoto(in, file);
		}
}

here is the chooseFile method I had to make:

public void chooseFile (File file, PhotoAlbum theAlb) throws NullPointerException 
	{	
		BufferedReader in;
		try {
			in = new BufferedReader(new FileReader(file));
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			in = new BufferedReader(new FileReader(file));
			theAlb.readPhotoAlbum(in, theAlb, file);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

Edited 6 Years Ago by charlieruns: forgot a method

OMG. Is this because my buffered reader has been moved from the openFile method to the fileChooser in a whole new class?

It turned out that I wasnt even doing the thing anyway.
I was supposed to select a text file and read details about a photo in there.

Not pull all the photo files from a directory. That was about 3 hours of wasted time. haha. Thanks either way!

This question has already been answered. Start a new discussion instead.