ok.this is my code and its error!
//*****************
public void listAllFiles(String directory, DefaultMutableTreeNode parent, Boolean recursive) throws IOException {
try {
File[] children = new File(directory).listFiles();
// list all the files in the directory
for (int i = 0; i < children.length; i++) { // loop through each
DefaultMutableTreeNode node = new DefaultMutableTreeNode(children[i].getName());
// only display the node if it isn't a folder, and if this is a recursive call
if (children[i].isDirectory() && recursive) {
parent.add(node);
listAllFiles(children[i].getPath(), node, recursive);
// call again for the subdirectory
} else if (!children[i].isDirectory()) { // otherwise, if it isn't a directory
parent.add(node);
}
root = new DefaultMutableTreeNode(children[i].getName());
FileReader infile = new FileReader(children[i].getPath());
BufferedReader reader = new BufferedReader(infile);
String s = reader.readLine();
treenode = new DefaultMutableTreeNode(s);
while (s != null) {
if (treenode.getParent() == null) {
treenode = new DefaultMutableTreeNode(s);
treenode.setParent(root);
par = (DefaultMutableTreeNode) treenode.getParent();
par.add(treenode);
} else {
treenode = new DefaultMutableTreeNode(s);
par = (DefaultMutableTreeNode) treenode.getParent();
par.add(treenode);
}
s = reader.readLine();
}
reader.close();
infile.close();
}
} catch (IOException e) {
JOptionPane.showMessageDialog(rootPane, "Error in reading file");
}
}
//**********
IllegalArgumentException:Argument is not a child!