本文整理汇总了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());
}
}
示例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;
}
示例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);
}
}
}
}
}
示例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();
}
}
示例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.");
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
}
示例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();
}
}
示例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();
}
示例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;
}