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


Java File.listFiles方法代码示例

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


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

示例1: getEtr

import java.io.File; //导入方法依赖的package包/类
public Collection<String> getEtr(){
	Collection<File> res = new LinkedList<File>();
	File[] listdir = new File(Engine.PROJECTS_PATH).listFiles();
	for(File s : listdir){
		File tracedir = new File(s,"Traces");
		if(tracedir.exists()&&tracedir.isDirectory()){
			File[] listconnectors = tracedir.listFiles();
			for(File s2 : listconnectors){
				res.addAll(Arrays.asList(s2.listFiles(new FilenameFilter(){
					public boolean accept(File arg0, String arg1) {
						return arg1.endsWith(".etr");
					}
				})));
			}
		}
	}
	Collection<String> listetr = new ArrayList<String>(res.size());
	for(File f : res)
		listetr.add(f.getPath().substring(Engine.PROJECTS_PATH.length()));
	return listetr;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:22,代码来源:TracePlayerManager.java

示例2: getFolderSize

import java.io.File; //导入方法依赖的package包/类
public static long getFolderSize(File file) throws Exception {
  long size = 0;
  try {
    File[] fileList = file.listFiles();
    for (int i = 0; i < fileList.length; i++) {
      // 如果下面还有文件
      if (fileList[i].isDirectory()) {
        size = size + getFolderSize(fileList[i]);
      } else {
        size = size + fileList[i].length();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return size;
}
 
开发者ID:lwd1815,项目名称:Selector,代码行数:18,代码来源:DataCleanManager.java

示例3: run

import java.io.File; //导入方法依赖的package包/类
private void run(final String prefix, final MessageDigest messageDigest) throws IOException {
    if (inputs == null) {
        println(prefix, DigestUtils.digest(messageDigest, System.in));
        return;
    }
    for(final String source : inputs) {
        final File file = new File(source);
        if (file.isFile()) {
            println(prefix, DigestUtils.digest(messageDigest, file), source);
        } else if (file.isDirectory()) {
            final File[] listFiles = file.listFiles();
            if (listFiles != null) {
                run(prefix, messageDigest, listFiles);
            }
        } else {
            // use the default charset for the command-line parameter
            final byte[] bytes = source.getBytes(Charset.defaultCharset());
            println(prefix, DigestUtils.digest(messageDigest, bytes));
        }
    }
}
 
开发者ID:HTBridge,项目名称:pivaa,代码行数:22,代码来源:Digest.java

示例4: findJarFile

import java.io.File; //导入方法依赖的package包/类
/**
 * 寻找目录下的jar文件
 * @param scriptLibDir
 * @return
 */
protected List<File> findJarFile(String scriptLibDir) {
	List<File> files = new ArrayList<File>();
	try {
		File file = new File(scriptLibDir);
		if (file.isDirectory()) {
			for (File f : file.listFiles()) {
				if (f.isFile() && f.getName().endsWith(".jar")) {
					files.add(f);
				}
			}
		}
	} catch (Exception e) {
		_log.error(e.getMessage(), e);
	}
	return files;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:22,代码来源:AbstractLibScriptFactory.java

示例5: getFolderSize

import java.io.File; //导入方法依赖的package包/类
public static long getFolderSize(File dir) {
    if (dir.exists()) {
        long result = 0;
        File[] fileList = dir.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            // Recursive call if it's a directory
            if (fileList[i].isDirectory()) {
                result += getFolderSize(fileList[i]);
            } else {
                // Sum the file size in bytes
                result += fileList[i].length();
            }
        }
        return result; // return the file size
    }
    return 0;
}
 
开发者ID:SalmanTKhan,项目名称:MyAnimeViewer,代码行数:18,代码来源:FileUtils.java

示例6: getAllDiskCacheFile

import java.io.File; //导入方法依赖的package包/类
/**
 * 获取所有缓存文件,判断依据:文件名开头cache_并且文件名结尾.data
 *
 * @return 返回列表,长度0则为空
 */
public List<File> getAllDiskCacheFile() {
	List<File> allFiles = new ArrayList<>();
	File cacheDir = new File(Pluto.SDPATH + "cache/");

	if (cacheDir.exists()) {
		File[] files = cacheDir.listFiles();
		for (File file : files) {
			String fileName = file.getName();
			if (fileName.startsWith("cache_") && fileName.endsWith(".data")) {
				allFiles.add(file);
			}
		}
	}

	return allFiles;
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:22,代码来源:PlutoFileCache.java

示例7: moveFiles

import java.io.File; //导入方法依赖的package包/类
private void moveFiles(File root) throws IOException {
    if (null == root || !root.exists()) {
        return;
    }

    File[] files = root.listFiles();
    for (File tmp : files) {

        if (tmp.isDirectory() &&
                tmp.getName().startsWith("drawable-") &&
                tmp.getName().endsWith("dpi")) {
            File toDir = new File(root, tmp.getName() + "-v4");
            toDir.mkdirs();

            FileUtils.copyDirectory(tmp, toDir);
            FileUtils.deleteDirectory(tmp);
        }
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:20,代码来源:MergeResV4Dir.java

示例8: clearTmp

import java.io.File; //导入方法依赖的package包/类
public synchronized static void clearTmp() {
    final File dir = new File(tmpPath.substring(0, tmpPath.length() - 1));
    final File l = dir;
    if (l.isDirectory() && !".".equals(l.getName())
            && !"..".equals(l.getName())) {
        boolean rem = true;
        final File[] fs = l.listFiles();
        for (final File f : fs) {
            if (f.getName().equals(".locked")) {
                if (!f.delete())
                    rem = false;
            }
        }
        if (rem)
            recRomove(l);
    }
    dir.delete();
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:19,代码来源:Options.java

示例9: clearFilesOnPath

import java.io.File; //导入方法依赖的package包/类
public static boolean clearFilesOnPath(String path) {
  File dir = new File(path);

  if (!dir.exists()) {
    System.out.println(path + " does not exists");
    return false;
  }

  if (!dir.isDirectory()) {
    System.out.println(path + " is not directory");
    return false;
  }

  File[] files = dir.listFiles();

  System.out.println("deleting " + path + " (" + files.length + " files)");

  for (int i = 0; i < files.length; i++) {
    if (files[i].isFile()) {
      // System.out.println("deleting " + files[i] );
      if (!files[i].delete()) {
        return false;
      }
    }
  }

  return true;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:29,代码来源:PathUtil.java

示例10: deleteDirectory

import java.io.File; //导入方法依赖的package包/类
private static boolean deleteDirectory(File path) {
  if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
      if (files[i].isDirectory()) {
        deleteDirectory(files[i]);
      } else {
        files[i].delete();
      }
    }
  }
  return path.delete();
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:14,代码来源:TPCC.java

示例11: actionPerformed

import java.io.File; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    String action = e.getActionCommand();

    if(action.equals(VERSION_CHOOSER)) {
        File mc = new File(minecraftPath.getText());
        File versions = new File(mc, "versions");

        JDialog dialog = new JDialog();

        dialog.setTitle("Select a Version");
        dialog.setLayout(new GridBagLayout());

        GridBagConstraints c = new GridBagConstraints();
        c.insets = new Insets(5, 5, 5, 5);
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;

        version = new JComboBox();
        for(File f : versions.listFiles()) {
            if(f.isDirectory()) version.addItem(f.getName());
        }
        dialog.add(version, c);

        JButton install = new JButton("Install");
        install.setActionCommand(INSTALL);
        install.addActionListener(this);
        dialog.add(install, c);

        Dimension d = dialog.getPreferredSize();
        dialog.setSize(new Dimension(d.width + 50, d.height + 50));
        dialog.setLocationRelativeTo(this);

        dialog.setVisible(true);
    } else if(action.equals(INSTALL)) {
        //TODO
    }
}
 
开发者ID:Guichaguri,项目名称:SkinFixer,代码行数:39,代码来源:SkinInstaller.java

示例12: calcDirSize

import java.io.File; //导入方法依赖的package包/类
public static long calcDirSize(File dir) { //取得文件夹大�?
    long size = 0;
    File flist[] = dir.listFiles();
    for (int i = 0; i < flist.length; i++) {
        if (flist[i].isDirectory()) {
            size = size + calcDirSize(flist[i]);
        } else {
            size = size + flist[i].length();
        }
    }
    return size;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:13,代码来源:CXPFileUtils.java

示例13: listFilesInDirWithFilter

import java.io.File; //导入方法依赖的package包/类
/**
 * 获取目录下所有后缀名为suffix的文件
 * <p>大小写忽略</p>
 *
 * @param dir         目录
 * @param suffix      后缀名
 * @param isRecursive 是否递归进子目录
 * @return 文件链表
 */
public static List<File> listFilesInDirWithFilter(File dir, String suffix, boolean isRecursive) {
    if (isRecursive) return listFilesInDirWithFilter(dir, suffix);
    if (dir == null || !isDir(dir)) return null;
    List<File> list = new ArrayList<>();
    File[] files = dir.listFiles();
    if (files != null && files.length != 0) {
        for (File file : files) {
            if (file.getName().toUpperCase().endsWith(suffix.toUpperCase())) {
                list.add(file);
            }
        }
    }
    return list;
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:24,代码来源:FileUtils.java

示例14: addDirToCache

import java.io.File; //导入方法依赖的package包/类
/**
 * Add the .jar elements of a directory to the DCache classpath, optionally
 * recursively.
 */
private static void addDirToCache(File dir, FileSystem fs,
  Set<String> localUrls, boolean recursive) {
  if (dir == null) {
    return;
  }

  File[] fileList = dir.listFiles();

  if (fileList == null) {
    LOG.warn("No files under " + dir
      + " to add to distributed cache for hcatalog job");
    return;
  }

  for (File libFile : dir.listFiles()) {
    if (libFile.exists() && !libFile.isDirectory()
      && libFile.getName().endsWith("jar")) {
      Path p = new Path(libFile.toString());
      if (libFile.canRead()) {
        String qualified = p.makeQualified(fs).toString();
        LOG.info("Adding to job classpath: " + qualified);
        localUrls.add(qualified);
      } else {
        LOG.warn("Ignoring unreadable file " + libFile);
      }
    }
    if (recursive && libFile.isDirectory()) {
      addDirToCache(libFile, fs, localUrls, recursive);
    }
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:36,代码来源:SqoopHCatUtilities.java

示例15: getFolderSize

import java.io.File; //导入方法依赖的package包/类
/**
 * 根据文件夹路径,获得该路径指向的文件夹的大小。
 * 遍历该文件夹及其子目录的文件,将这些文件的大小进行累加,得出的就是文件夹的大小。
 *
 * @param path
 * @return
 * @throws FileNotFoundException
 */
public static long getFolderSize(String path) throws FileNotFoundException {
    path = separatorReplace(path);
    long size = 0;
    File folder = getFolder(path);
    File[] files = folder.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            size += getFolderSize(file.getAbsolutePath());
        } else if (file.isFile()) {
            size += file.length();
        }
    }
    return size;
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:23,代码来源:FileUtil.java


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