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();
}
}