public File getChild(File parent, String fileName) { return createFileObject(parent, fileName); }
public File createFileObject(String path) { File f = new File(path); if (isFileSystemRoot(f)) { f = createFileSystemRoot(f); } return f; }
public boolean isFileSystemRoot(File dir) { return isRoot(dir); }
public File getParentDirectory(File dir) { if (dir != null && dir.exists()) { File psf = dir.getParentFile(); if (psf != null) { if (isFileSystem(psf)) { File f = psf; if (!f.exists()) { File ppsf = psf.getParentFile(); if (ppsf == null || !isFileSystem(ppsf)) { f = createFileSystemRoot(f); } } return f; } else { return psf; } } } return null; }
public boolean isRoot(File f) { if (f == null || !f.isAbsolute()) { return false; } File[] roots = getRoots(); for (File root : roots) { if (root.equals(f)) { return true; } } return false; }
public File[] getFiles(File dir, boolean useFileHiding) { Vector<File> files = new Vector<>(); File[] names; names = dir.listFiles(); File f; int nameCount = (names == null) ? 0 : names.length; for (int i = 0; i < nameCount; i++) { if (Thread.currentThread().isInterrupted()) { break; } f = names[i]; if (!useFileHiding || !isHiddenFile(f)) { files.addElement(f); } } return files.toArray(new File[0]); }
public static JFileChooser createJFileChooser() { if(isWindows()) { // workaround // https://bugs.openjdk.java.net/browse/JDK-8179014 UIManager.put("FileChooser.useSystemExtensionHiding", false); } JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception npe) { log.info("Working around http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6210674 and 6544857 by using Metal UI and restricted file system view"); UIManager.getDefaults().put("FileChooserUI", "javax.swing.plaf.metal.MetalFileChooserUI"); chooser = new JFileChooser(new RestrictedFileSystemView()); } return chooser; }
public File getHomeDirectory() { return createFileObject(System.getProperty("user.home")); }
public String getSystemDisplayName(File f) { String name = null; if (f != null) { if (isRoot(f)) { name = f.getAbsolutePath(); } else { name = f.getName(); } } return name; }
public File createNewFolder(File containingDir) throws IOException { if (containingDir == null) throw new IOException("Containing directory is null:"); File newFolder = createFileObject(containingDir, newFolderString); int i = 2; while (newFolder.exists() && (i < 100)) { newFolder = createFileObject(containingDir, MessageFormat.format(newFolderString, i)); i++; } if (newFolder.exists()) { throw new IOException("Directory already exists:" + newFolder.getAbsolutePath()); } else { newFolder = ensureDirectory(newFolder); } return newFolder; } }