public void setFileName(int row, String name) { // avoid moving a File by renaming it !! if (name.indexOf("..") < 0 && name.indexOf("/") < 0 && name.indexOf("\\") < 0) { File oldFile = getFile(filenames[row]); File newFile = new File(oldFile.getParent() + File.separator + name); filenames[row] = name; oldFile.renameTo(newFile); } }
public void setDirectory(File d, FilenameFilter f) { if (d == null || !d.isDirectory()) { directory = null; filenames = new String[0]; } else { if (f != null) { filenameFilter = f; } directory = d; filenames = directory.list(filenameFilter); if (filenames != null) { // cannot access directory ? Arrays.sort(filenames); dirType = new boolean[filenames.length]; for (int i = 0; i < filenames.length; ++i) { // I hate generating objects like this.. dirType[i] = (new File(d, filenames[i])).isDirectory(); } } else { filenames = new String[0]; } } fireTableStructureChanged(); }