Example usage for java.io File listRoots

List of usage examples for java.io File listRoots

Introduction

In this page you can find the example usage for java.io File listRoots.

Prototype

public static File[] listRoots() 

Source Link

Document

List the available filesystem roots.

Usage

From source file:Main.java

static String getRootDirectoryPath() {
    return File.listRoots().length == 1 ? File.listRoots()[0].getPath().trim() : "";
}

From source file:Main.java

public static File getLastDirectory() {
    if (lastDirectory == null) {
        String home = System.getProperty("user.home");
        lastDirectory = home != null && !home.isEmpty() ? new File(home) : File.listRoots()[0];
    }/*from   www  .j av a  2  s .  c o m*/
    return lastDirectory;
}

From source file:Main.java

static String getParentPath(String path) {
    File file = new File(path);
    String parent = file.getParent();
    if (parent == null) {
        File[] roots = File.listRoots();
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].equals(file)) {
                parent = getRootDirectoryPath();
                break;
            }/*from  w ww  .jav a 2  s  .  co m*/
        }
    }
    return parent;
}

From source file:TestingNonApplication.TestMainNonApp.java

public static void testListRoots() {
    File[] drives = File.listRoots();
    for (File file : drives) {
        System.out.println(file.toString());
        /* Printed out:/*from w ww  .java2 s.co  m*/
         C:\
         D:\
         */
    }
}

From source file:pl.otros.vfs.browser.favorit.FavoritesUtils.java

public static List<Favorite> getSystemLocations() {
    ArrayList<Favorite> list = new ArrayList<Favorite>();
    File[] listRoots = File.listRoots();
    for (File file : listRoots) {
        list.add(new Favorite(file.getAbsolutePath(), file.getAbsolutePath(), Favorite.Type.SYSTEM));
    }//  w  w w  . java 2  s . c  o  m

    list.add(new Favorite("Home", new File(System.getProperty("user.home")).getAbsolutePath(),
            Favorite.Type.SYSTEM));
    return list;
}

From source file:TestingNonApplication.TestMainNonApp.java

/**
 * File Testing//from   ww  w  .  j  a v  a  2  s.com
 * -------------------------------------------------------------------
 */
public static void nanoTestFileScane() {
    File[] drives = File.listRoots();

    long startTime1 = System.nanoTime();
    for (File file : drives) {
        hyperAVAJAVAFileMp3Scan(file);
    }
    long estimatedTime1 = System.nanoTime() - startTime1;

    long startTime2 = System.nanoTime();
    for (File file : drives) {
        hyperStackOverflowFileMp3Scan(file);
    }
    long estimatedTime2 = System.nanoTime() - startTime2;

    System.out.println("Estimated time 1: " + estimatedTime1);
    System.out.println("Estimated time 2: " + estimatedTime2);
    long smallestTime = Math.min(estimatedTime1, estimatedTime2);
    System.out.println("Shortest Time: " + smallestTime);
}

From source file:org.duracloud.syncui.controller.JQueryFileTreeController.java

@RequestMapping(value = { "/ajax/jqueryFileTree" })
public String get(@RequestParam(value = "dir", required = false) String dir, Model model) throws Exception {
    // if blank/*from w  ww  .  j a v a 2  s  .  co m*/
    List<File> children = new ArrayList<File>();
    model.addAttribute("children", children);

    if (StringUtils.isBlank(dir)) {
        File[] roots = File.listRoots();

        // display roots if more than one
        if (roots.length > 1) {
            // otherwise display the list of multiple roots (windows)
            children.addAll(Arrays.asList(roots));
        } else {
            loadChildren(roots[0], children);
        }
    } else {
        if (dir.charAt(dir.length() - 1) == '\\') {
            dir = dir.substring(0, dir.length() - 1) + "/";
        } else if (dir.charAt(dir.length() - 1) != '/') {
            dir += "/";
        }

        dir = java.net.URLDecoder.decode(dir, "UTF-8");
        File directory = new File(dir);
        loadChildren(directory, children);
    }

    return "jqueryFileTree";
}

From source file:Main.java

/**
 * Does a basic calculation on the number of threads you can concuurently
 * run given the desired Cpu Usage, the Cpu wait time, and the Cpu calc
 * time. For slower threaded tasks, such as downloading large files, etc,
 * you may pass in a large number for cpuWaitTime vs. cpuCalcTime (if
 * processing the of data takes .1 X the time it takes to download for
 * example)//from www . j a  v a 2  s .com
 * 
 * @param cpuUsagePct
 *            a float between 0 and 1
 * @param cpuWaitTime
 *            a float
 * @param cpuCalcTime
 *            a float
 * @return the number of concurrent threads that can run with likely
 *         stability given the parameters.
 */
public static int getStableThreadCount(float cpuUsagePct, float cpuWaitTime, float cpuCalcTime,
        int maxThreads) {

    // number of processor cores
    int cores = Runtime.getRuntime().availableProcessors();

    // number of disks on the file system (known)
    File[] paths;

    // returns pathnames for files and directory
    paths = File.listRoots();
    int disks = paths.length;

    // c can be 0 -> N
    double c = (cpuWaitTime > 0 && cpuCalcTime > 0) ? cpuWaitTime / cpuCalcTime : 0;
    // final thread calculation
    int numThreads = (int) (2 * cores * disks * cpuUsagePct * (1 + c));
    // clamp the max threads between 1 and MAX_THREADS

    numThreads = Math.max(1, numThreads);
    if (maxThreads > 0) {
        numThreads = Math.min(maxThreads, numThreads);
    }

    System.out.println("Getting Stable thread count:" + numThreads);

    return numThreads;
}

From source file:FileTree2.java

public FileTree2() {
    super("Directories Tree [Popup Menus]");
    setSize(400, 300);/*from w  ww  . j ava2 s .c o m*/

    DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer"));

    DefaultMutableTreeNode node;
    File[] roots = File.listRoots();
    for (int k = 0; k < roots.length; k++) {
        node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k])));
        top.add(node);
        node.add(new DefaultMutableTreeNode(new Boolean(true)));
    }

    m_model = new DefaultTreeModel(top);
    m_tree = new JTree(m_model);

    m_tree.putClientProperty("JTree.lineStyle", "Angled");

    TreeCellRenderer renderer = new IconCellRenderer();
    m_tree.setCellRenderer(renderer);

    m_tree.addTreeExpansionListener(new DirExpansionListener());

    m_tree.addTreeSelectionListener(new DirSelectionListener());

    m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    m_tree.setShowsRootHandles(true);
    m_tree.setEditable(false);

    JScrollPane s = new JScrollPane();
    s.getViewport().add(m_tree);
    getContentPane().add(s, BorderLayout.CENTER);

    m_display = new JTextField();
    m_display.setEditable(false);
    getContentPane().add(m_display, BorderLayout.NORTH);

    // NEW
    m_popup = new JPopupMenu();
    m_action = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (m_clickedPath == null)
                return;
            if (m_tree.isExpanded(m_clickedPath))
                m_tree.collapsePath(m_clickedPath);
            else
                m_tree.expandPath(m_clickedPath);
        }
    };
    m_popup.add(m_action);
    m_popup.addSeparator();

    Action a1 = new AbstractAction("Delete") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree2.this, "Delete option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a1);

    Action a2 = new AbstractAction("Rename") {
        public void actionPerformed(ActionEvent e) {
            m_tree.repaint();
            JOptionPane.showMessageDialog(FileTree2.this, "Rename option is not implemented", "Info",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    };
    m_popup.add(a2);
    m_tree.add(m_popup);
    m_tree.addMouseListener(new PopupTrigger());

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:Testing.TestMain.java

public static void testCDrive() {
    //        DirectoryStream directoryStream(directoryStream);
    File cDrive = new File("D:\\");
    File[] drives = File.listRoots();

    for (File drive : drives) {
        for (File rootDirectory : drives) {
            File directory = new File(rootDirectory.getPath());
            System.out.println("PATH: " + directory.toString());
        }/*from w w  w . j a  v  a  2  s .c  o m*/
    }
}