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:view.MainWindow.java

private void populateDriveComboBox() {
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();

    if (SystemUtils.IS_OS_WINDOWS) {
        File[] roots;//from  w w w .j a  v  a2s  . c  o  m
        roots = File.listRoots();
        if (roots.length > 1) {
            for (File root : roots) {
                dcbm.addElement(root.getAbsolutePath());
            }
            dcbm.addElement(System.getProperty("user.name"));
            dcbm.addElement(Bundle.getBundle().getString("desktop"));
            jtExplorer.setModel(new FileSystemModel(new File(roots[0].getAbsolutePath()), null));
        }
    } else {
        String userDir = System.getProperty("user.home");
        dcbm.addElement("/");
        dcbm.addElement(userDir);
        jtExplorer.setModel(new FileSystemModel(new File(userDir), null));
    }
    cbVolume.setModel(dcbm);
    cbVolume.adjustDropDownMenuWidth();
}

From source file:wordnice.utils.JavaUtils.java

public static File getJDK() {
    File lastChance = null;//from   w  w w .  j av  a  2  s . c o m

    String ver = "jdk" + (System.getProperty("java.version").toLowerCase());

    String jdk = System.getenv("JAVA_HOME");
    if (jdk != null && !jdk.isEmpty() && ver != null) {
        lastChance = new File(jdk);
        if (lastChance.exists() && lastChance.getName().toLowerCase().contains(ver)) {
            return lastChance;
        }
    }

    String os = System.getProperty("os.name");
    boolean isWin = (os != null && (os.contains("win") || os.contains("Win")));
    if (!isWin) {
        String response = executeAndGetOutput("whereis", "javac");
        if (response != null && !response.isEmpty()) {
            int pathStartIndex = response.indexOf('/');
            if (pathStartIndex != -1) {
                String[] paths = response.substring(pathStartIndex, response.length()).split(" ");
                for (int i = 0, n = paths.length; i < n; i++) {
                    String path = paths[i];
                    if (!path.endsWith("javac")) {
                        continue;
                    }
                    lastChance = FilesAPI.readFinalLink(new File(path)).getParentFile().getParentFile();
                    if (lastChance.exists()) {
                        return lastChance;
                    }
                }
            }
        }
        if (lastChance == null) {
            lastChance = getJRE().getParentFile();
        }
    } else {
        String path = executeAndGetOutput("where.exe", "javac");
        if (path != null && !path.isEmpty()) {
            lastChance = new File(path).getParentFile().getParentFile();
            if (lastChance.exists() && lastChance.getName().toLowerCase().contains(ver)) {
                return lastChance;
            }
        }

        if (ver == null) {
            return lastChance;
        }
        path = System.getenv("PATH");
        if (path == null) {
            path = System.getenv("Path");
        }

        if (path != null) {
            String[] paths = path.split(File.pathSeparator);
            for (int i = 0, n = paths.length; i < n; i++) {
                String p = paths[i];
                if (p.toLowerCase().contains(ver)) {
                    File f = new File(p);
                    if (f.exists()) {
                        return f;
                    } else if (lastChance == null) {
                        lastChance = f;
                    }
                }
            }
        }

        File[] roots = File.listRoots();
        if (roots == null || roots.length == 0) {
            return null;
        }
        File jp = new File(roots[0], "Program Files/Java/");
        if (!jp.exists() || !jp.isDirectory()) {
            jp = new File(roots[0], "Program Files (x86)/Java/");
            if (!jp.exists() || !jp.isDirectory()) {
                return null;
            }
        }
        File[] jvs = jp.listFiles();
        if (jvs == null || jvs.length == 0) {
            return null;
        }
        if (jvs.length == 1) {
            return jvs[0];
        }
        for (int i = 0, n = jvs.length; i < n; i++) {
            File f = jvs[i];
            String nm = f.getName().toLowerCase();
            if (nm.contains(ver)) {
                return f;
            } else if (nm.contains("jdk")) {
                if (lastChance == null || !lastChance.exists()) {
                    lastChance = f;
                }
            }
        }
    }
    if (lastChance == null) {
        if (jdk != null && !jdk.isEmpty()) {
            lastChance = new File(jdk);
        }
    }
    return lastChance;
}

From source file:ConnectionInfo.java

protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FillLayout());

    // the vertical sashform.
    SashForm verticalForm = new SashForm(composite, SWT.VERTICAL);

    // the horizontal sashform.
    SashForm horizontalForm = new SashForm(verticalForm, SWT.HORIZONTAL);

    // Local dir browser.
    Composite compositeLocalDir = new Composite(horizontalForm, SWT.NULL);
    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 1;/* w  w w  .  ja  v  a 2 s .co m*/
    gridLayout.verticalSpacing = 1;
    compositeLocalDir.setLayout(gridLayout);

    Group compositeLocalDirTop = new Group(compositeLocalDir, SWT.NULL);
    compositeLocalDirTop.setText("Local");
    GridLayout gridLayout2 = new GridLayout(3, false);
    gridLayout2.marginHeight = 0;
    compositeLocalDirTop.setLayout(gridLayout2);
    compositeLocalDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    labelPathLocal = new Label(compositeLocalDirTop, SWT.NULL);
    labelPathLocal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    labelPathLocal.setText("Path: ");

    Button buttonUpLocalDir = new Button(compositeLocalDirTop, SWT.PUSH);
    buttonUpLocalDir.setText(actionUpLocalDir.getText());
    buttonUpLocalDir.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            actionUpLocalDir.run();
        }
    });

    Button buttonBrowseLocalDir = new Button(compositeLocalDirTop, SWT.PUSH);
    buttonBrowseLocalDir.setText(actionBrowseLocalDir.getText());
    buttonBrowseLocalDir.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            actionBrowseLocalDir.run();
        }
    });

    Table table = new Table(compositeLocalDir, SWT.BORDER);
    TableColumn tcFile = new TableColumn(table, SWT.LEFT);
    tcFile.setText("Name");

    TableColumn tcSize = new TableColumn(table, SWT.NULL);
    tcSize.setText("Size");

    TableColumn tcDate = new TableColumn(table, SWT.NULL);
    tcDate.setText("Date");

    tcFile.setWidth(200);
    tcSize.setWidth(100);
    tcDate.setWidth(100);
    table.setHeaderVisible(true);

    table.setLayoutData(new GridData(GridData.FILL_BOTH));
    localDirBrowser = new LocalDirectoryBrowser(table);

    table.addListener(SWT.MouseDoubleClick, new Listener() {
        public void handleEvent(Event event) {
            IStructuredSelection selection = (IStructuredSelection) localDirBrowser.getSelection();
            File file = (File) selection.getFirstElement();
            if (file != null && file.isDirectory()) {
                localDirBrowser.setInput(file);
                labelPathLocal.setText("Path: " + file);
            }
        }
    });

    // Remote directory browser.

    Composite compositeRemoteDir = new Composite(horizontalForm, SWT.NULL);
    gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 1;
    gridLayout.verticalSpacing = 1;
    compositeRemoteDir.setLayout(gridLayout);

    Group compositeRemoteDirTop = new Group(compositeRemoteDir, SWT.NULL);
    compositeRemoteDirTop.setText("Remote");
    gridLayout2 = new GridLayout(2, false);
    gridLayout2.marginHeight = 0;
    compositeRemoteDirTop.setLayout(gridLayout2);
    compositeRemoteDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    labelPathRemote = new Label(compositeRemoteDirTop, SWT.NULL);
    labelPathRemote.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    labelPathRemote.setText("Path: ");

    Button buttonUpRemoteDir = new Button(compositeRemoteDirTop, SWT.PUSH);
    buttonUpRemoteDir.setText(actionUpLocalDir.getText());
    buttonUpRemoteDir.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            actionUpRemoteDir.run();
        }
    });

    Table tableRemote = new Table(compositeRemoteDir, SWT.BORDER);
    TableColumn tcFileRemote = new TableColumn(tableRemote, SWT.LEFT);
    tcFileRemote.setText("Name");

    TableColumn tcSizeRemote = new TableColumn(tableRemote, SWT.NULL);
    tcSizeRemote.setText("Size");

    TableColumn tcDateRemote = new TableColumn(tableRemote, SWT.NULL);
    tcDateRemote.setText("Date");

    tcFileRemote.setWidth(200);
    tcSizeRemote.setWidth(100);
    tcDateRemote.setWidth(100);
    tableRemote.setHeaderVisible(true);

    tableRemote.setLayoutData(new GridData(GridData.FILL_BOTH));
    remoteDirBrowser = new RemoteDirectoryBrowser(tableRemote);

    tableRemote.addListener(SWT.MouseDoubleClick, new Listener() {
        public void handleEvent(Event event) {
            IStructuredSelection selection = (IStructuredSelection) remoteDirBrowser.getSelection();
            FTPFile file = (FTPFile) selection.getFirstElement();
            if (file != null && file.isDirectory()) {
                try {
                    ftp.changeWorkingDirectory(file.getName());
                    labelPathRemote.setText("Path: " + ftp.printWorkingDirectory());
                    remoteDirBrowser.setInput(ftp.listFiles());
                } catch (IOException e) {
                    logError(e.toString());
                }
            }
        }
    });

    // the log box.
    textLog = new StyledText(verticalForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

    localDirBrowser.setInput(File.listRoots()[0]);
    labelPathLocal.setText("Path: " + File.listRoots()[0]);

    // resize sashform children.
    verticalForm.setWeights(new int[] { 4, 1 });

    // adding drag and drop support.
    dragNDropSupport();

    getToolBarControl().setBackground(new Color(getShell().getDisplay(), 230, 230, 230));

    getShell().setImage(new Image(getShell().getDisplay(), "icons/ftp/ftp.gif"));
    getShell().setText("FTP Client v1.0");

    return composite;
}

From source file:gtu._work.ui.DirectoryCompareUI.java

private String getStarTeamPath_FileCompareMerge(boolean ifEmptyThrow) {
    String starTeamStr = null;/* w ww .  j  ava2s . com*/
    for (File root : File.listRoots()) {
        if (root.listFiles() == null) {
            continue;
        }
        for (File chkRoot : root.listFiles()) {
            File tempExe = new File(chkRoot,
                    "Borland/StarTeam Cross-Platform Client 2008 R2/File Compare Merge.exe");
            if (tempExe.exists()) {
                try {
                    starTeamStr = tempExe.getCanonicalPath();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    if (configBean.getConfigProp().containsKey(STARTEAM_KEY)) {
        starTeamStr = configBean.getConfigProp().getProperty(STARTEAM_KEY);
    }
    if (StringUtils.isBlank(starTeamStr) && ifEmptyThrow) {
        throw new RuntimeException("??starTeam \"File Compare Merge.exe\"");
    }
    return starTeamStr;
}

From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java

/**
 * ?//from   w  w w  . j a  v a2  s .  c o m
 * 
 * @return
 */
private List getLocalFileRoots() {
    List listroots = new ArrayList();
    File[] roots = File.listRoots();
    for (File file : roots) {
        if (file.getTotalSpace() <= 0)
            continue;
        TreeData treedata = new TreeData(file.getPath());
        Map attr = new HashMap();
        attr.put("path", file.getPath());
        attr.put("totalSpace", CommonUtils.formatterDiskSize(file.getTotalSpace()));
        attr.put("freeSpace", CommonUtils.formatterDiskSize(file.getFreeSpace()));
        treedata.setId(file.getPath());
        treedata.setAttributes(attr);
        listroots.add(treedata);
    }
    return listroots;
}

From source file:fr.msch.wissl.server.REST.java

@GET
@Path("folders/listing")
public String getFolderListing(@QueryParam("directory") String directory) throws SecurityError, SQLException {
    long l1 = System.nanoTime();
    String sid = (sessionIdHeader == null ? sessionIdGet : sessionIdHeader);
    Session sess = Session.check(sid, request.getRemoteAddr(), userAgent, true);
    StringBuilder ret = new StringBuilder();

    File dir = null;//from   w  w  w  .ja v  a  2s  .com
    File[] l = null;
    String dirName = null;

    if (directory == null || directory.trim().length() == 0) {
        dir = new File(System.getProperty("user.home"));
        l = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        dirName = dir.getAbsolutePath();
    } else if (directory.equals("$ROOT")) {
        dirName = "";
        l = File.listRoots();
    } else {
        dir = new File(directory);

        if (!dir.exists()) {
            throw new NotFoundException("Unknown directory: " + directory);
        } else if (!dir.isDirectory()) {
            throw new IllegalArgumentException("Not a directory: " + directory);
        }

        l = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return pathname.isDirectory();
            }
        });
        dirName = dir.getAbsolutePath();
    }

    ret.append("{\"directory\":" + JSONObject.quote(dirName));
    ret.append(",\"separator\":" + JSONObject.quote(File.separator));
    if (dir != null && dir.getParent() != null) {
        ret.append(",\"parent\":" + JSONObject.quote(dir.getParent()));
    } else {
        ret.append(",\"parent\":" + JSONObject.quote("$ROOT"));
    }
    ret.append(",\"listing\":[");
    if (l != null) {
        Arrays.sort(l);
        boolean virgule = false;
        for (int i = 0; i < l.length; i++) {
            if (l[i].exists()) {
                if (virgule) {
                    ret.append(',');
                }
                virgule = (i + 1 < l.length);
                ret.append(JSONObject.quote(l[i].getAbsolutePath()));
            }
        }
    }
    ret.append("]}");

    nocache();
    log(sess, l1);
    return ret.toString();
}

From source file:base.BasePlayer.Main.java

public void openPleiades(String pleiadesurl) {
    boolean bamonly = false;
    String pleiades = pleiadesurl.trim();
    if (pleiades.toLowerCase().startsWith("bam")) {
        bamonly = true;// www .  j  a v a  2  s .com
        pleiades = pleiades.replace("bam", "").trim();
    }

    if (pleiades.contains("`")) {
        pleiades.replace("`", "?");
    }
    if (pleiades.contains(" ")) {
        pleiades.replace(" ", "%20");
    }
    if (pleiades.contains("pleiades")) {
        try {
            URL url = new URL(pleiadesurl.trim());
            //System.out.println(Main.chooserText);
            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
            httpConn.connect();

            int responseCode = httpConn.getResponseCode();

            if (responseCode == HttpsURLConnection.HTTP_OK) {

                String loading = drawCanvas.loadingtext;
                InputStream inputStream = httpConn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
                Main.drawCanvas.loadingtext = loading + " 0MB";
                String line;
                StringBuffer buffer = new StringBuffer("");
                while ((line = reader.readLine()) != null) {

                    buffer.append(line);

                }
                inputStream.close();
                reader.close();
                String split2;
                String[] split = buffer.toString().split("dataUnit");
                String location;
                ArrayList<File> array = new ArrayList<File>();
                File[] paths;
                FileSystemView fsv = FileSystemView.getFileSystemView();
                paths = File.listRoots();
                String loc = "/mnt";
                boolean missingfiles = false;
                for (File path : paths) {
                    if (fsv.getSystemDisplayName(path).contains("merit")) {
                        loc = path.getCanonicalPath();
                    }
                }

                for (int i = 0; i < split.length; i++) {

                    if (!split[i].contains("lastLocation")) {

                        continue;
                    }

                    split2 = split[i].split("\"lastLocation\":\"")[1];
                    location = split2.substring(0, split2.indexOf("\"}"));
                    String filename = "";
                    String testloc = location.replace("/mnt", loc) + "/wgspipeline/";
                    File testDir = new File(testloc);
                    if (testDir.exists() && testDir.isDirectory()) {
                        if (bamonly) {
                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                public boolean accept(File dir, String name) {
                                    return name.toLowerCase().endsWith(".bam")
                                            || name.toLowerCase().endsWith(".cram");
                                }
                            });
                            if (addDir.length > 0) {
                                filename = addDir[0].getName();
                            }
                        } else {
                            File[] addDir = testDir.listFiles(new FilenameFilter() {
                                public boolean accept(File dir, String name) {
                                    return name.toLowerCase().endsWith(".vcf.gz");
                                }
                            });
                            if (addDir.length > 0) {
                                filename = addDir[0].getName();
                            }
                        }
                    }

                    location = testloc + "/" + filename;

                    if (!new File(location).exists()) {

                        if (!new File(location).exists()) {
                            missingfiles = true;
                            ErrorLog.addError("No sample files found in " + testloc);

                        } else {
                            array.add(new File(location));
                        }
                    } else {

                        array.add(new File(location));
                    }
                }

                File[] files = new File[array.size()];
                for (int i = 0; i < files.length; i++) {

                    files[i] = array.get(i);
                }
                FileRead filereader = new FileRead(files);
                filereader.start = (int) drawCanvas.selectedSplit.start;
                filereader.end = (int) drawCanvas.selectedSplit.end;
                if (bamonly) {
                    filereader.readBAM = true;
                } else {
                    filereader.readVCF = true;
                }
                filereader.execute();
                if (missingfiles) {
                    JOptionPane.showMessageDialog(Main.drawScroll, "Missing files. Check Tools->View log",
                            "Note", JOptionPane.INFORMATION_MESSAGE);
                }

            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    return;

}

From source file:net.sf.jvifm.ui.FileLister.java

private File[] getReadAbleRoots() {
    ArrayList<File> rootList = new ArrayList<File>();
    for (File file : File.listRoots()) {
        if (file.canRead()) {
            rootList.add(file);//from  ww w  . ja v a 2s .c o m
        }
    }
    return rootList.toArray(new File[] {});
}

From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java

public void promptForNewVfsRoot() {
    boolean done = false;
    String defaultText = vfsBrowser.rootFileObject.getName().getURI();
    String text = defaultText;//  ww w.j a v a 2 s.  c o  m
    while (!done) {
        if (text == null) {
            text = defaultText;
        }
        File fileRoots[] = File.listRoots();
        String roots[] = new String[fileRoots.length];
        for (int i = 0; i < roots.length; i++) {
            try {
                roots[i] = fileRoots[i].toURI().toURL().toExternalForm();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        ComboBoxInputDialog textDialog = new ComboBoxInputDialog(
                Messages.getString("VfsFileChooserDialog.enterNewVFSRoot"), text, roots, 650, 100); //$NON-NLS-1$
        text = textDialog.open();
        if (text != null && !"".equals(text)) { //$NON-NLS-1$
            try {
                vfsBrowser.resetVfsRoot(currentPanel.resolveFile(text));
                done = true;
            } catch (FileSystemException e) {
                MessageBox errorDialog = new MessageBox(vfsBrowser.getDisplay().getActiveShell(), SWT.OK);
                errorDialog.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$
                errorDialog.setMessage(e.getMessage());
                errorDialog.open();
            }
        } else {
            done = true;
        }
    }
}

From source file:br.org.indt.ndg.client.Service.java

public ArrayList<String> listRoots() {
    File[] roots = File.listRoots();
    ArrayList<String> list = new ArrayList<String>();

    for (int i = 0; i < roots.length; i++) {
        list.add(roots[i].toString());/* w ww  .j  a v a 2s.  com*/
    }

    return list;
}