当前位置: 首页>>代码示例>>Java>>正文


Java File.listRoots方法代码示例

本文整理汇总了Java中java.io.File.listRoots方法的典型用法代码示例。如果您正苦于以下问题:Java File.listRoots方法的具体用法?Java File.listRoots怎么用?Java File.listRoots使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.File的用法示例。


在下文中一共展示了File.listRoots方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: FileSystemProfile

import java.io.File; //导入方法依赖的package包/类
private FileSystemProfile() {
    super(ProfileManager.LOCAL_FILESYSTEM_PROFILE_ID, DEFAULT_FILESYSTEM_PROFILE_NAME);
    File[] roots = File.listRoots();

    if (roots != null && roots.length == 1) {
        // One root - probably a Unix filesystem. Set this as the ROOT_PATH
        ROOT_PATH = roots[0].getPath();
    } else {
        File current = new File(System.getProperty("user.dir"));
        File root = current.getParentFile();
        while (root.getParentFile() != null) {
            root = root.getParentFile();
        }
        ROOT_PATH = root.getPath();
    }
    displayedPath = ConfigurationHelper.getStringProperty(LOCAL_FILESYSTEM_PATH,
                                                          System.getProperty("user.home"));

}
 
开发者ID:Hitachi-Data-Systems,项目名称:Open-DM,代码行数:20,代码来源:FileSystemProfile.java

示例2: testValidRoots

import java.io.File; //导入方法依赖的package包/类
public void testValidRoots () throws Exception {
    assertNotNull(testedFS.getRoot());    
    assertTrue(testedFS.getRoot().isValid());            
    
    FileSystemView fsv = FileSystemView.getFileSystemView();                
    File[] roots = File.listRoots();
    boolean validRoot = false;
    for (int i = 0; i < roots.length; i++) {
        FileObject root1 = FileUtil.toFileObject(roots[i]);
        if (!roots[i].exists()) {
           assertNull(root1);
           continue; 
        }
        
        assertNotNull(roots[i].getAbsolutePath (),root1);
        assertTrue(root1.isValid());
        if (testedFS == root1.getFileSystem()) {
            validRoot = true;
        }
    }
    assertTrue(validRoot);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BaseFileObjectTestHid.java

示例3: CreateTreeView

import java.io.File; //导入方法依赖的package包/类
@Override
public void CreateTreeView(TreeView<String> treeview){
    File[] sysroots = File.listRoots();
    TreeItem<String> ThisPc = new TreeItem<>("This PC", new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/pc.png"))));
    TreeItem<String>[] drives = new TreeItem[sysroots.length];
    for(int i=0; i<sysroots.length;i++){
        drives[i] = new TreeItem<>(sysroots[i].getAbsolutePath(), new ImageView(new Image(ClassLoader.getSystemResourceAsStream("img/thumb_Hard_Drive.png"))));
        try{
            drives[i].getChildren().addAll(TreeCreate(sysroots[i]));
        }catch(NullPointerException x){System.out.println("Exeption x detected: "+x.fillInStackTrace()+drives[i].toString());}
        finally {
            ThisPc.getChildren().add(drives[i]);
        }
    }
    treeview.setRoot(ThisPc);
}
 
开发者ID:maximstewart,项目名称:UDE,代码行数:17,代码来源:ClassTreeView.java

示例4: testListRoots

import java.io.File; //导入方法依赖的package包/类
public void testListRoots() {
    for (File f : File.listRoots()) {
        String n = f.getPath();
        if (n.length() <= 1) {
            continue;
        }
        
        String withoutN;
        if (n.endsWith(File.separator)) {
            withoutN = n.substring(0, n.length() - 1);
        } else {
            continue;
        }
        FileNaming fWith = NamingFactory.fromFile(f);
        FileNaming fWithout = NamingFactory.fromFile(new File(withoutN));
        
        assertEquals("Roots should be the same", fWith, fWithout);
        if (Utilities.isWindows()) {
            FileNaming fUpper = NamingFactory.fromFile(new File(f.getPath().toUpperCase(Locale.ENGLISH)));
            FileNaming fLower = NamingFactory.fromFile(new File(f.getPath().toLowerCase(Locale.ENGLISH)));
            assertEquals("Lower and Upper case roots are equal on Windows", fUpper, fLower);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FileNameTest.java

示例5: get

import java.io.File; //导入方法依赖的package包/类
/**
 * @param key a {@code String}
 *  "fileChooserDefaultFolder":
 *    Returns a {@code File} - the default shellfolder for a new filechooser
 *  "roots":
 *    Returns a {@code File[]} - containing the root(s) of the displayable hierarchy
 *  "fileChooserComboBoxFolders":
 *    Returns a {@code File[]} - an array of shellfolders representing the list to
 *    show by default in the file chooser's combobox
 *   "fileChooserShortcutPanelFolders":
 *    Returns a {@code File[]} - an array of shellfolders representing well-known
 *    folders, such as Desktop, Documents, History, Network, Home, etc.
 *    This is used in the shortcut panel of the filechooser on Windows 2000
 *    and Windows Me.
 *  "fileChooserIcon <icon>":
 *    Returns an {@code Image} - icon can be ListView, DetailsView, UpFolder, NewFolder or
 *    ViewMenu (Windows only).
 *
 * @return An Object matching the key string.
 */
public Object get(String key) {
    if (key.equals("fileChooserDefaultFolder")) {
        // Return the default shellfolder for a new filechooser
        File homeDir = new File(System.getProperty("user.home"));
        try {
            return createShellFolder(homeDir);
        } catch (FileNotFoundException e) {
            return homeDir;
        }
    } else if (key.equals("roots")) {
        // The root(s) of the displayable hierarchy
        return File.listRoots();
    } else if (key.equals("fileChooserComboBoxFolders")) {
        // Return an array of ShellFolders representing the list to
        // show by default in the file chooser's combobox
        return get("roots");
    } else if (key.equals("fileChooserShortcutPanelFolders")) {
        // Return an array of ShellFolders representing well-known
        // folders, such as Desktop, Documents, History, Network, Home, etc.
        // This is used in the shortcut panel of the filechooser on Windows 2000
        // and Windows Me
        return new File[] { (File)get("fileChooserDefaultFolder") };
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:ShellFolderManager.java

示例6: constructRoots

import java.io.File; //导入方法依赖的package包/类
private static void constructRoots() {
    if (osName.startsWith("windows")) {
        Vector rootsVector = new Vector();
    
        // Create the A: drive whether it is mounted or not
        FileSystemRoot floppy = new FileSystemRoot("A" + ":" + "\\");
        rootsVector.addElement(floppy);

        // Run through all possible mount points and check
        // for their existance.
        for (char c = 'C'; c <= 'Z'; c++) {
            char device[] = {c, ':', '\\'};
            String deviceName = new String(device);
            File deviceFile = new FileSystemRoot(deviceName);
            if (deviceFile != null && deviceFile.exists()) {
                rootsVector.addElement(deviceFile);
            }
        }
        roots = new File[rootsVector.size()];
        rootsVector.copyInto(roots);
    } else {
        roots = File.listRoots();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:25,代码来源:MyUtility.java

示例7: isMountPoint

import java.io.File; //导入方法依赖的package包/类
/**
 * @param file
 *            Canonical file to match. Never <code>null</code>.
 * @return Whether the specified file matches a filesystem root.
 * @throws IOException
 */
public static boolean isMountPoint(final File file) {
    for (final File root : File.listRoots()) {
        if (root.equals(file)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:15,代码来源:StorageManager.java

示例8: getSysSize

import java.io.File; //导入方法依赖的package包/类
/**
 * 获取系统各盘符大小
 */
public Map<String, Double> getSysSize() {
	File[] files = File.listRoots();
	Map<String, Double> map = null;
	for(int i = 0; i < files.length; i++) {
		 map = new HashMap<String, Double>();
		 long total = (long) files[i].getTotalSpace();  
            long free = (long) files[i].getFreeSpace();
            Double compare = (Double) (1 - free * 1.0 / total) * 100;
            map.put(files[i].getName(), compare);
	}
	return map;
}
 
开发者ID:Awesky,项目名称:awe-awesomesky,代码行数:16,代码来源:SystemMonitorUtil.java

示例9: suite

import java.io.File; //导入方法依赖的package包/类
public static Test suite() {
    NbTestSuite ts = new NbTestSuite();
    if (Utilities.isWindows()) {
        for (File root : File.listRoots()) {
            ts.addTest(new CreateFileOnWindowsTest(root));
        }
    }
    return ts;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:CreateFileOnWindowsTest.java

示例10: DiskService

import java.io.File; //导入方法依赖的package包/类
public DiskService() {
    File[] diskRoots = File.listRoots();
    disks = new ArrayList<>();
    for(File file: diskRoots) {
        disks.add(new Disk(file));
    }
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:8,代码来源:DiskService.java

示例11: testFlat

import java.io.File; //导入方法依赖的package包/类
public void testFlat() {
    File f = File.listRoots()[0];
    VCSFileProxy proxy = VCSFileProxy.createFileProxy(f);
    assertFalse(APIAccessor.IMPL.isFlat(proxy));
    proxy = Utils.createFlatFileProxy(FileUtil.toFileObject(f));
    assertTrue(APIAccessor.IMPL.isFlat(proxy));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:VersioningSupportTest.java

示例12: getDriver

import java.io.File; //导入方法依赖的package包/类
public static List<String> getDriver() {
    List<String> driverList = new ArrayList<>();
    File[] fs = File.listRoots();

    for (int i = 0; i < fs.length; i++) {
        driverList.add(fs[i].getAbsolutePath());
    }
    return driverList;
}
 
开发者ID:neal1991,项目名称:everywhere,代码行数:10,代码来源:FileUtil.java

示例13: getFileSystems

import java.io.File; //导入方法依赖的package包/类
private static FileSystem[] getFileSystems() {
    List<FileSystem> retval = new ArrayList<FileSystem>();
    for (File file : File.listRoots()) {
        FileObject fo = FileUtil.toFileObject(file);
        if (fo != null) {
            try {
                retval.add(fo.getFileSystem());
            } catch (FileStateInvalidException ex) {
                    LOG.log(Level.INFO, null, ex);
            }
        }
    }        
    return retval.toArray(new FileSystem[retval.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:I18nOptions.java

示例14: getChildDirList

import java.io.File; //导入方法依赖的package包/类
@RequestMapping("/getChildDirList")
public ResultInfo getChildDirList(@RequestParam String model,
    @RequestBody(required = false) DirInfo body) {
  ResultInfo resultInfo = new ResultInfo();
  List<DirInfo> data = new LinkedList<>();
  resultInfo.setData(data);
  File[] files;
  if (body == null || StringUtils.isEmpty(body.getPath())) {
    files = File.listRoots();
  } else {
    File file = new File(body.getPath());
    if (file.exists() && file.isDirectory()) {
      files = file.listFiles();
    } else {
      resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("路径不存在");
      return resultInfo;
    }
  }
  if (files != null && files.length > 0) {
    boolean isFileList = "file".equals(model);
    for (File tempFile : files) {
      if (tempFile.isFile()) {
        if (isFileList) {
          data.add(new DirInfo(
              StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath()
                  : tempFile.getName(), tempFile.getAbsolutePath(), true));
        }
      } else if (tempFile.isDirectory() && (tempFile.getParent() == null || !tempFile
          .isHidden())) {
        DirInfo dirInfo = new DirInfo(
            StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath()
                : tempFile.getName(), tempFile.getAbsolutePath(),
            tempFile.listFiles() == null ? true : Arrays.stream(tempFile.listFiles())
                .noneMatch(file ->
                    file != null && (file.isDirectory() || isFileList) && !file.isHidden()
                ));
        data.add(dirInfo);
      }
    }
  }
  return resultInfo;
}
 
开发者ID:monkeyWie,项目名称:proxyee-down,代码行数:43,代码来源:HttpDownController.java

示例15: getAllPossibleValues

import java.io.File; //导入方法依赖的package包/类
@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType,
    String existingData, String optionContext, MethodTarget target) {
  // prefix is needed while comparing Completion Candidates as potential matches
  String prefixToUse = "";
  boolean prependAbsolute = true;
  File parentDir = null; // directory to be searched for file(s)

  if (existingData != null) {
    // System.out.println("FilePathConverter.getAllPossibleValues() : optionContext ::
    // "+optionContext+", existingData : "+existingData);
    String[] completionValues = new String[0];

    if (ConverterHint.DIR_PATHSTRING.equals(optionContext)) {
      // if existingData is empty, start from root
      if (existingData != null && existingData.trim().isEmpty()) {
        File[] listRoots = File.listRoots();
        completionValues = new String[listRoots.length];
        for (int i = 0; i < listRoots.length; i++) {
          if (listRoots[i].isDirectory()) {
            completionValues[i] = listRoots[i].getPath();
          }
        }
        prefixToUse = File.separator;
      } else {
        // Create a file from existing data
        File file = new File(existingData);
        if (file.isDirectory()) {
          // For a directory, list files/sub-dirs in the directory
          parentDir = file;
          completionValues = parentDir.list(dirFilter);
        } else if (!file.exists()) {
          parentDir = file.getParentFile();
          if (parentDir == null) {
            try {
              parentDir = file.getCanonicalFile().getParentFile();
            } catch (IOException e) {
              parentDir = null;
            }
          }
          if (parentDir != null) {
            completionValues = parentDir.list(new DirNameFilterImpl(parentDir, file.getName()));
          }
        }
        // whether the file path is absolute
        prependAbsolute = file.isAbsolute();
      }
    }

    if (completionValues.length > 0) {
      // use directory path as prefix for completion of names of the contained files
      if (parentDir != null) {
        if (existingData.startsWith(".")) { // handle . & ..
          prefixToUse = parentDir.getPath();
        } else if (prependAbsolute) {
          prefixToUse = parentDir.getAbsolutePath();
        }
      }
      // add File.separator in the end
      if (!prefixToUse.endsWith(File.separator)
          && (prependAbsolute || existingData.startsWith("."))) {
        prefixToUse += File.separator;
      }
      for (int i = 0; i < completionValues.length; i++) {
        completions.add(new Completion(prefixToUse + completionValues[i]));
      }
    }
  }

  return !completions.isEmpty();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:72,代码来源:DirPathConverter.java


注:本文中的java.io.File.listRoots方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。