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


Java File.list方法代码示例

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


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

示例1: init

import java.io.File; //导入方法依赖的package包/类
/**
 * Initialize our set of users and home directories.
 */
private void init() {

	String homeBase = userConfig.getHomeBase();
	File homeBaseDir = new File(homeBase);
	if (!homeBaseDir.exists() || !homeBaseDir.isDirectory())
		return;
	String homeBaseFiles[] = homeBaseDir.list();
	if (homeBaseFiles == null) {
		return;
	}

	for (int i = 0; i < homeBaseFiles.length; i++) {
		File homeDir = new File(homeBaseDir, homeBaseFiles[i]);
		if (!homeDir.isDirectory() || !homeDir.canRead())
			continue;
		homes.put(homeBaseFiles[i], homeDir.toString());
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:HomesUserDatabase.java

示例2: deleteFile

import java.io.File; //导入方法依赖的package包/类
public static boolean deleteFile(File file) {
    if (file.exists() && file.isFile() && file.canWrite()) {
        return file.delete();
    } else if (file.isDirectory()) {
        if (null != file && file.list() != null && file.list().length == 0) {
            return file.delete();
        } else {
            String[] fileList = file.list();
            for (String filePaths : fileList) {
                File tempFile = new File(file.getAbsolutePath() + "/" + filePaths);
                if (tempFile.isFile()) {
                    tempFile.delete();
                } else {
                    deleteFile(tempFile);
                    tempFile.delete();
                }
            }

        }
        if (file.exists()) {
            return file.delete();
        }
    }
    return false;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:26,代码来源:FileUtils.java

示例3: zipDir

import java.io.File; //导入方法依赖的package包/类
private static void zipDir(File dir, String relativePath, ZipOutputStream zos,
                           boolean start) throws IOException {
  String[] dirList = dir.list();
  for (String aDirList : dirList) {
    File f = new File(dir, aDirList);
    if (!f.isHidden()) {
      if (f.isDirectory()) {
        if (!start) {
          ZipEntry dirEntry = new ZipEntry(relativePath + f.getName() + "/");
          zos.putNextEntry(dirEntry);
          zos.closeEntry();
        }
        String filePath = f.getPath();
        File file = new File(filePath);
        zipDir(file, relativePath + f.getName() + "/", zos, false);
      }
      else {
        String path = relativePath + f.getName();
        if (!path.equals(JarFile.MANIFEST_NAME)) {
          ZipEntry anEntry = new ZipEntry(path);
          copyToZipStream(f, anEntry, zos);
        }
      }
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:JarFinder.java

示例4: delete

import java.io.File; //导入方法依赖的package包/类
private static void delete(File file) throws IOException {
    if (file.isDirectory()) {
        //directory is empty, then delete it
        if (file.list().length == 0) {
            file.delete();
        } else {
            //list all the directory contents
            String files[] = file.list();
            for (String temp : files) {
                //construct the file structure
                File fileDelete = new File(file, temp);

                //recursive delete
                delete(fileDelete);
            }
            //check the directory again, if empty then delete it
            if (file.list().length == 0) {
                file.delete();
            }
        }

    } else {
        //if file, then delete it
        file.delete();
    }
}
 
开发者ID:datathings,项目名称:greycat,代码行数:27,代码来源:StorageTest.java

示例5: addResourcesToClasspath

import java.io.File; //导入方法依赖的package包/类
/**
 * Adds content of the directory specified with 'path' to the classpath. It
 * does so by creating a new instance of the {@link URLClassLoader} using
 * {@link URL}s created from listing the contents of the directory denoted
 * by 'path' and setting it as thread context class loader.
 */
static void addResourcesToClasspath(String path) {
    if (logger.isDebugEnabled()) {
        logger.debug("Adding additional resources from '" + path + "' to the classpath.");
    }
    if (path == null) {
        throw new IllegalArgumentException("'path' must not be null");
    }
    File libraryDir = new File(path);
    if (libraryDir.exists() && libraryDir.isDirectory()) {
        String[] cpResourceNames = libraryDir.list();
        URL[] urls = new URL[cpResourceNames.length];
        try {
            for (int i = 0; i < urls.length; i++) {
                urls[i] = new File(libraryDir, cpResourceNames[i]).toURI().toURL();
                if (logger.isDebugEnabled()) {
                    logger.debug("Identifying additional resource to the classpath: " + urls[i]);
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException(
                    "Failed to parse user libraries from '" + libraryDir.getAbsolutePath() + "'", e);
        }

        URLClassLoader cl = new URLClassLoader(urls, Utils.class.getClassLoader());
        Thread.currentThread().setContextClassLoader(cl);
    } else {
        throw new IllegalArgumentException("Path '" + libraryDir.getAbsolutePath()
                + "' is not valid because it doesn't exist or does not point to a directory.");
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:37,代码来源:Utils.java

示例6: restore

import java.io.File; //导入方法依赖的package包/类
public static BackupStats restore(FileSystem fs, Path backupDir, DACConfig dacConfig) throws Exception {
  final String dbDir = dacConfig.getConfig().getString(DremioConfig.DB_PATH_STRING);
  URI uploads = dacConfig.getConfig().getURI(DremioConfig.UPLOADS_PATH_STRING);
  File dbPath = new File(dbDir);

  if (!dbPath.isDirectory() || dbPath.list().length > 0) {
    throw new IllegalArgumentException(format("Path %s must be an empty directory.", dbDir));
  }
  final LocalKVStoreProvider localKVStoreProvider = new LocalKVStoreProvider(ClassPathScanner.fromPrescan(dacConfig.getConfig().getSabotConfig()), dbDir, false, true, false, true);
  localKVStoreProvider.start();
  // TODO after we add home file store type to configuration make sure we change homefile store construction.
  if(uploads.getScheme().equals("pdfs")){
    uploads = UriBuilder.fromUri(uploads).scheme("file").build();
  }
  final HomeFileConfig homeFileStore = new HomeFileConfig(uploads, dacConfig.getMasterNode());
  homeFileStore.createFileSystem();
  Map<String, BackupFileInfo> tableToInfo = scanInfoFiles(fs, backupDir);
  Map<String, Path> tableToBackupFiles = scanBackupFiles(fs, backupDir, tableToInfo);
  final BackupStats backupStats = new BackupStats();
  backupStats.backupPath = backupDir.toUri().getPath();

  for (String table : tableToInfo.keySet()) {
    final StoreBuilderConfig storeBuilderConfig = DataStoreUtils.toBuilderConfig(tableToInfo.get(table).getKvstoreInfo());
    final CoreKVStore<?, ?> store = localKVStoreProvider.getOrCreateStore(storeBuilderConfig);
    restoreTable(fs, store, tableToBackupFiles.get(table));
    ++backupStats.tables;
  }

  restoreUploadedFiles(fs, backupDir, homeFileStore, backupStats);
  localKVStoreProvider.close();

  return backupStats;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:34,代码来源:BackupRestoreUtil.java

示例7: getChildren

import java.io.File; //导入方法依赖的package包/类
@Override
public List<String> getChildren(String path) throws Exception {
  File file = new File(path);
  String[] children = file.list();
  if (children == null || children.length == 0) {
    return new ArrayList<>();
  }
  return Arrays.asList(children);
}
 
开发者ID:Microsoft,项目名称:pai,代码行数:10,代码来源:MockZooKeeperClient.java

示例8: children

import java.io.File; //导入方法依赖的package包/类
protected String[] children(String name) {
    File f = getFile(name);

    if (f.isDirectory()) {
        return f.list();
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:LocalFileSystem.java

示例9: deleteFolder

import java.io.File; //导入方法依赖的package包/类
/**
 * deleteFolder
 * 
 * @param path
 * @return
 */
public static int deleteFolder(String path) {

    int res = 1;
    File dir = new File(path);

    String[] files = dir.list();

    if (files != null && files.length > 0) {

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

            File temp = new File(path + "/" + files[i]);

            if (temp.isDirectory()) {
                res += deleteFolder(temp.getAbsolutePath());
            }

            try {
                temp.delete();
            }
            catch (Exception ee) {
                return -1;
            }
        }

    }

    dir.delete();

    return res;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:38,代码来源:IOHelper.java

示例10: copyDirectory

import java.io.File; //导入方法依赖的package包/类
public void copyDirectory(File sourceLocation , File targetLocation)
throws IOException {

    if (sourceLocation.isDirectory()) {
        if (!targetLocation.exists()) {
            targetLocation.mkdir();
        }

        String[] children = sourceLocation.list();
        for (int i=0; i<children.length; i++) {
            copyDirectory(new File(sourceLocation, children[i]),
                    new File(targetLocation, children[i]));
        }
    } else {

        InputStream in = new FileInputStream(sourceLocation);
        OutputStream out = new FileOutputStream(targetLocation);

        // Copy the bits from instream to outstream
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }
}
 
开发者ID:EdgarLopezPhD,项目名称:PaySim,代码行数:29,代码来源:DatabaseHandler.java

示例11: validateFolder

import java.io.File; //导入方法依赖的package包/类
@Messages({"LBL_Folder_Error=Folder not empty. The folder must be empty to continue.", "LBL_Folder=Local working copy path"})
private void validateFolder() {

    File file = new File(txtFolder.getText().trim());
    if (file.exists() && file.list() != null && file.list().length > 0) {
        checkoutButton.setEnabled(false);
        lblFolderError.setForeground(Color.red);
        lblFolderError.setText(LBL_Folder_Error());
    } else {
        lblFolderError.setText(LBL_Folder());
        checkoutButton.setEnabled(true);
        lblFolderError.setForeground(Color.BLACK);
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CheckoutUI.java

示例12: fillPath

import java.io.File; //导入方法依赖的package包/类
/**
 * Method declaration
 *
 *
 * @param path
 * @param name
 * @param prep
 *
 * @throws SQLException
 */
static void fillPath(String path, String name,
                     PreparedStatement prep) throws SQLException {

    File f = new File(path);

    if (f.isFile()) {

        // Clear all Parameters of the PreparedStatement
        prep.clearParameters();

        // Fill the first parameter: Path
        prep.setString(1, path);

        // Fill the second parameter: Name
        prep.setString(2, name);

        // Its a file: add it to the table
        prep.execute();
    } else if (f.isDirectory()) {
        if (!path.endsWith(File.separator)) {
            path += File.separator;
        }

        String[] list = f.list();

        // Process all files recursivly
        for (int i = 0; (list != null) && (i < list.length); i++) {
            fillPath(path + list[i], list[i], prep);
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:42,代码来源:FindFile.java

示例13: deleteDir

import java.io.File; //导入方法依赖的package包/类
public static boolean deleteDir(File dir) {
    if (dir != null && dir.isDirectory()) {
        String[] files = dir.list();
        for (String file : files) {
            boolean success = deleteDir(new File(dir, file));
            if (!success) {
                return false;
            }
        }
        return dir.delete();
    } else {
        return dir != null && dir.isFile() && dir.delete();
    }
}
 
开发者ID:qqq3,项目名称:inventum,代码行数:15,代码来源:AppUtils.java

示例14: clearDirectory

import java.io.File; //导入方法依赖的package包/类
private void clearDirectory(File file){
    String[] children = file.list();
    for (int i = 0; i < children.length; i++) {
        new File(file, children[i]).delete();
    }
    cameraInitializer.setCurrentImagesNumber(0);
    numberOfImagesTextView.setText("0");
    Toast.makeText(MainActivity.this.getApplicationContext(),
            getString(R.string.directory_clear_toast_message),
            Toast.LENGTH_SHORT).show();
}
 
开发者ID:PawelTypiak,项目名称:Checkerboard-IMU-Comparator,代码行数:12,代码来源:MainActivity.java

示例15: findChildrenList

import java.io.File; //导入方法依赖的package包/类
/**
 * 获目录下的文件列表
 *
 * @param dir        搜索目录
 * @param searchDirs 是否是搜索目录
 * @return 文件列表
 */
public static List<String> findChildrenList(File dir, boolean searchDirs) {
	List<String> files = Lists.newArrayList();
	for (String subFiles : dir.list()) {
		File file = new File(dir + "/" + subFiles);
		if (((searchDirs) && (file.isDirectory())) || ((!searchDirs) && (!file.isDirectory()))) {
			files.add(file.getName());
		}
	}
	return files;
}
 
开发者ID:funtl,项目名称:framework,代码行数:18,代码来源:FileUtils.java


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