List of usage examples for java.io File listRoots
public static File[] listRoots()
From source file:su.fmi.photoshareclient.ui.PhotoViewDialog.java
private void SaveImageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveImageButtonMouseClicked JFileChooser fileChooser = new JFileChooser() { // A warning for overweiting existing files @Override//from w w w. j a va 2 s .com public void approveSelection() { File f = getSelectedFile(); if (f.exists() && getDialogType() == SAVE_DIALOG) { int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; fileChooser.setDialogTitle("Save image as..."); File rootVolume = File.listRoots()[0]; fileChooser.setSelectedFile(new File(rootVolume.getAbsolutePath(), this.imageLabel.getFileName())); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { try { File fileToSave = fileChooser.getSelectedFile(); BufferedImage bi = (BufferedImage) this.imageLabel.getImage(); String ext = FilenameUtils.getExtension(fileToSave.getAbsolutePath()); ImageIO.write(bi, ext, fileToSave); } catch (IOException ex) { Logger.getLogger(PhotoViewDialog.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:se.trixon.filebydate.Operation.java
public void start() { long startTime = System.currentTimeMillis(); Date date = new Date(startTime); SimpleDateFormat dateFormat = new SimpleDateFormat(); mListener.onOperationStarted();/*from w w w . ja v a 2 s .c o m*/ mListener.onOperationProcessingStarted(); mListener.onOperationLog(dateFormat.format(date)); mInterrupted = !generateFileList(); String status; if (!mInterrupted && !mFiles.isEmpty()) { mListener.onOperationLog(String.format(mBundle.getString("found_count"), mFiles.size())); mListener.onOperationLog(""); status = Dict.PROCESSING.toString(); mListener.onOperationLog(status); int progress = 0; SimpleDateFormat simpleDateFormat = mProfile.getDateFormat(); for (File sourceFile : mFiles) { try { try { TimeUnit.MILLISECONDS.sleep(1); } catch (InterruptedException ex) { mInterrupted = true; break; } String fileDate = simpleDateFormat.format(getDate(sourceFile)); File destDir = new File(mProfile.getDestDir(), fileDate); if (destDir.isFile()) { mListener.onOperationLog(String.format(Dict.Dialog.ERROR_DEST_DIR_IS_FILE.toString(), destDir.getAbsolutePath())); break; } else if (!destDir.exists() && !mProfile.isDryRun()) { FileUtils.forceMkdir(destDir); } String destFilename = sourceFile.getName(); String base = FilenameUtils.getBaseName(destFilename); String ext = FilenameUtils.getExtension(destFilename); NameCase caseBase = mProfile.getCaseBase(); NameCase caseExt = mProfile.getCaseExt(); if (caseBase != NameCase.UNCHANGED || caseExt != NameCase.UNCHANGED) { if (caseBase == NameCase.LOWER) { base = base.toLowerCase(); } else if (caseBase == NameCase.UPPER) { base = base.toUpperCase(); } if (caseExt == NameCase.LOWER) { ext = ext.toLowerCase(); } else if (caseBase == NameCase.UPPER) { ext = ext.toUpperCase(); } if (base.length() == 0) { destFilename = String.format(".%s", ext); } else if (ext.length() == 0) { destFilename = base; } else { destFilename = String.format("%s.%s", base, ext); } } File destFile = new File(destDir, destFilename); String log; if (destFile.exists() && !mProfile.isReplaceExisting()) { log = String.format(Dict.Dialog.ERROR_DEST_FILE_EXISTS.toString(), destFile.getAbsolutePath()); } else { Command command = mProfile.getCommand(); String cmd = command == Command.COPY ? "cp" : "mv"; log = String.format("%s %s %s", cmd, sourceFile.getAbsolutePath(), destFile.toString()); if (destDir.canWrite()) { if (!mProfile.isDryRun()) { if (command == Command.COPY) { FileUtils.copyFile(sourceFile, destFile); } else if (command == Command.MOVE) { if (File.listRoots().length > 1 || destFile.exists()) { FileUtils.copyFile(sourceFile, destFile); FileUtils.deleteQuietly(sourceFile); } else { FileUtils.moveFile(sourceFile, destFile); } } } } else if (!mProfile.isDryRun()) { log = Dict.Dialog.ERROR_DEST_CANT_WRITE.toString(); } } mListener.onOperationLog(getMessage(log)); } catch (IOException | ImageProcessingException | NullPointerException ex) { mListener.onOperationLog(getMessage(ex.getLocalizedMessage())); } mListener.onOperationProgress(++progress, mFiles.size()); } } if (mInterrupted) { status = Dict.TASK_ABORTED.toString(); mListener.onOperationLog("\n" + status); mListener.onOperationInterrupted(); } else { mExceptions.stream().forEach((exception) -> { mListener.onOperationLog(String.format("#%s", exception.getLocalizedMessage())); }); long millis = System.currentTimeMillis() - startTime; long min = TimeUnit.MILLISECONDS.toMinutes(millis); long sec = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)); status = String.format("%s (%d %s, %d %s)", Dict.TASK_COMPLETED.toString(), min, Dict.TIME_MIN.toString(), sec, Dict.TIME_SEC.toString()); mListener.onOperationFinished(status, mFiles.size()); if (!mProfile.isDryRun()) { mProfile.setLastRun(System.currentTimeMillis()); try { ProfileManager.getInstance().save(); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } } } }
From source file:org.rhq.augeas.util.Glob.java
public static String rootPortion(String path) { File[] roots = File.listRoots(); if (roots != null) { for (File root : roots) { if (path.startsWith(root.getPath())) { return root.getPath(); }/*from ww w. j ava 2 s . co m*/ } } else { log.warn("Could not determine file system roots. This is strange."); } return ""; }
From source file:com.apress.dwrprojects.fileman.FileSystemFunctions.java
/** * This method is called to list all the file system roots on the system. * * @return A List of DirectoryVO objects, one for each file system * root on the system. * @throws Exception If anything goes wrong. *//*from w w w . j a v a 2 s .c om*/ public List listRoots() throws Exception { try { File[] roots = File.listRoots(); List<DirectoryVO> results = new ArrayList<DirectoryVO>(); for (final File f : roots) { DirectoryVO dv = new DirectoryVO(); dv.setName(f.getPath()); dv.setPath(f.getPath()); // See if the directory has child directories or not. Anonymous inner // class used to determine whether the directory has children or not. String[] childDirectories = f.list(new FilenameFilter() { public boolean accept(final File inDir, final String inName) { if (inName != f.getName()) { File f = new File(inDir.getPath() + File.separator + inName); if (f.isDirectory()) { return true; } else { return false; } } else { return false; } } }); // Setting whether the directory has children or not is used by the UI // code to set up the grid properly in terms of nodes being expandable // or not. if (childDirectories != null && childDirectories.length > 0) { dv.setHasChildren(true); } results.add(dv); } return results; } catch (Exception e) { throw new Exception("Exception occurred: " + e); } }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void createCustomUIPanel(final Shell dialog) { customUIPanel = new Composite(dialog, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); customUIPanel.setLayoutData(gridData); customUIPanel.setLayout(new GridLayout(1, false)); comboPanel = new Composite(customUIPanel, SWT.NONE); comboPanel.setLayoutData(gridData);/*from w w w . j a va 2s .com*/ comboPanel.setLayout(new GridLayout(2, false)); comboPanel.setData("donotremove"); Label lookInLabel = new Label(comboPanel, SWT.NONE); lookInLabel.setText(Messages.getString("VfsFileChooserDialog.LookIn")); gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false); lookInLabel.setLayoutData(gridData); customUIPicker = new Combo(comboPanel, SWT.READ_ONLY); gridData = new GridData(SWT.LEFT, SWT.CENTER, true, false); customUIPicker.setLayoutData(gridData); if (!showLocation) { comboPanel.setParent(fakeShell); } if (!showCustomUI) { customUIPanel.setParent(fakeShell); } customUIPicker.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { selectCustomUI(); } public void widgetDefaultSelected(SelectionEvent event) { selectCustomUI(); } }); customUIPicker.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent arg0) { selectCustomUI(); } public void keyPressed(KeyEvent arg0) { selectCustomUI(); } }); boolean createdLocal = false; for (CustomVfsUiPanel panel : customUIPanels) { if (panel.getVfsScheme().equals("file")) { createdLocal = true; } } if (!createdLocal) { CustomVfsUiPanel localPanel = new CustomVfsUiPanel("file", "Local", this, SWT.None) { public void activate() { try { File startFile = new File(System.getProperty("user.home")); if (startFile == null || !startFile.exists()) { startFile = File.listRoots()[0]; } FileObject dot = fsm.resolveFile(startFile.toURI().toURL().toExternalForm()); rootFile = dot.getFileSystem().getRoot(); selectedFile = rootFile; setInitialFile(selectedFile); openFileCombo.setText(selectedFile.getName().getURI()); resolveVfsBrowser(); } catch (Throwable t) { } } }; addVFSUIPanel(localPanel); } }
From source file:edu.harvard.i2b2.adminTool.dataModel.PatientIDConversionFactory.java
private String getNoteKeyDrive() { File[] drives = File.listRoots(); String filename = "i2b2patientidkey.txt"; for (int i = drives.length - 1; i >= 0; i--) { if (drives[i].getPath().startsWith("A") || drives[i].getPath().startsWith("B")) { continue; }/* w w w .j a v a 2s . c om*/ File tmp = new File(drives[i]/* +File.separator */ + filename); if (tmp.exists()) { return drives[i]/* +File.separator */ + filename; } // else { // return null; // } } File testFile = new File("i2b2patientidkey.txt"); System.out.println("file dir: " + testFile.getAbsolutePath()); if (testFile.exists()) { return testFile.getAbsolutePath(); } return null; }
From source file:CheckFileTree.java
/** * Gets the root element(s) of the tree//ww w . ja v a2s . c om * * @param arg0 * the input data * @return Object[] */ public Object[] getElements(Object arg0) { // These are the root elements of the tree // We don't care what arg0 is, because we just want all // the root nodes in the file system return File.listRoots(); }
From source file:tajo.master.MockupWorker.java
@Override public ServerStatusProto getServerStatus(PrimitiveProtos.NullProto request) { // serverStatus builder ServerStatusProto.Builder serverStatus = ServerStatusProto.newBuilder(); // TODO: compute the available number of task slots serverStatus.setAvailableTaskSlotNum(taskQueue.size()); // system(CPU, memory) status builder ServerStatusProto.System.Builder systemStatus = ServerStatusProto.System.newBuilder(); systemStatus.setAvailableProcessors(Runtime.getRuntime().availableProcessors()); systemStatus.setFreeMemory(Runtime.getRuntime().freeMemory()); systemStatus.setMaxMemory(Runtime.getRuntime().maxMemory()); systemStatus.setTotalMemory(Runtime.getRuntime().totalMemory()); serverStatus.setSystem(systemStatus); // disk status builder File[] roots = File.listRoots(); for (File root : roots) { ServerStatusProto.Disk.Builder diskStatus = ServerStatusProto.Disk.newBuilder(); diskStatus.setAbsolutePath(root.getAbsolutePath()); diskStatus.setTotalSpace(root.getTotalSpace()); diskStatus.setFreeSpace(root.getFreeSpace()); diskStatus.setUsableSpace(root.getUsableSpace()); serverStatus.addDisk(diskStatus); }//www .j a v a 2s . c om return serverStatus.build(); }
From source file:net.pms.dlna.RootFolder.java
private List<RealFile> getConfiguredFolders() { List<RealFile> res = new ArrayList<RealFile>(); File[] files = PMS.get().getFoldersConf(); if (files == null || files.length == 0) { files = File.listRoots(); }//from w w w. j a v a 2 s . c o m for (File f : files) { res.add(new RealFile(f)); } return res; }
From source file:com.googlecode.vfsjfilechooser2.filechooser.AbstractVFSFileSystemView.java
/** * Returns all root partitions on this system. For example, on * Windows, this would be the "Desktop" folder, while on DOS this * would be the A: through Z: drives.//from w ww.j av a 2 s .c om * @param fo * @return */ public FileObject[] getRoots(FileObject fo) { if (fo instanceof DecoratedFileObject) { fo = ((DecoratedFileObject) fo).getDecoratedFileObject(); } if (fo instanceof LocalFile) { File[] roots = File.listRoots(); final int count = roots.length; localRoots = new FileObject[roots.length]; for (int i = 0; i < count; i++) { localRoots[i] = VFSUtils.toFileObject(roots[i]); } return localRoots.clone(); } // Don't cache this array, because filesystem might change else { FileObject p = VFSUtils.getRootFileSystem(fo); return new FileObject[] { p }; } }