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


Java File.exists方法代码示例

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


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

示例1: ensureTargetFileIsValid

import java.io.File; //导入方法依赖的package包/类
/**
 * Returns a boolean indicating whether the passed File handle is is valid and available for use.
 */
protected boolean ensureTargetFileIsValid(File targetFile) {
	if (targetFile.exists() && targetFile.isDirectory()) {
		displayErrorDialog(N4ExportMessages.Export_mustBeFile);
		giveFocusToDestination();
		return false;
	}

	if (targetFile.exists()) {
		if (targetFile.canWrite()) {
			if (!this.overwriteExistingFilesCheckbox.getSelection()
					&& !queryYesNoQuestion(N4ExportMessages.Export_alreadyExists)) {
				return false;
			}
		} else {
			displayErrorDialog(N4ExportMessages.Export_alreadyExistsError);
			giveFocusToDestination();
			return false;
		}
	}
	return true;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:25,代码来源:AbstractExportToSingleFileWizardPage.java

示例2: createFromArchetype

import java.io.File; //导入方法依赖的package包/类
public static void createFromArchetype(File projDir, ProjectInfo vi, Archetype arch, @NullAllowed Map<String,String> additional, boolean updateLastUsedProjectDir) throws IOException {
    final File parent = projDir.getParentFile();
    if (parent == null) {
        throw new IOException("no parent of " + projDir);
    }
    if (updateLastUsedProjectDir && parent != null && parent.exists()) {
        ProjectChooser.setProjectsFolder(parent);
    }
    if (!parent.isDirectory() && !parent.mkdirs()) {
        throw new IOException("could not create " + parent);
    }
    runArchetype(parent, vi, arch, additional);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ArchetypeWizardUtils.java

示例3: databaseExists

import java.io.File; //导入方法依赖的package包/类
/**
 * Checks if the given database exists in the Derby system home.
 *
 * @return true if the database exists, false otherwise.
 *
 * @throws NullPointerException if <code>databaseName</code> is null.
 */
public  boolean databaseExists(String databaseName) {
    if (databaseName == null) {
        throw new NullPointerException("The databaseName parameter cannot be null"); // NOI18N
    }
    // just because it makes sense, not really needed anywhere probably
    if ("".equals(databaseName)) { // NOI18N
        return false;
    }

    String systemHome = DerbySupport.getSystemHome();
    if (systemHome.length() <= 0) { // NOI18N
        return false;
    }
    File databaseFile = new File(systemHome, databaseName);
    return databaseFile.exists();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:DerbyDatabasesImpl.java

示例4: findLibrary

import java.io.File; //导入方法依赖的package包/类
/**
 * Finds a native library. This method is called after the parent
 * ClassLoader has failed to find a native library of the same name.
 *
 * @param libname The name of the library to find
 * @return the complete path of the library, or {@code null} if the library
 * is not found.
 */
@Override
protected String findLibrary(String libname) {
    ensureInit();

    String fileName = System.mapLibraryName(libname);
    for (int i = 0; i < mLibPaths.length; i++) {
        String pathName = mLibPaths[i] + fileName;
        File test = new File(pathName);

        if (test.exists()) {
            if (VERBOSE_DEBUG)
                System.out.println("  found " + libname);
            return pathName;
        }
    }

    if (VERBOSE_DEBUG)
        System.out.println("  library " + libname + " not found");
    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:29,代码来源:DexClassLoader.java

示例5: createNewJarFile

import java.io.File; //导入方法依赖的package包/类
private File createNewJarFile (String prefix) throws IOException {
    if (prefix == null) {
        prefix = "modules";
    }
    
    File dir = new File(this.getWorkDir(), prefix);
    dir.mkdirs();
    
    int i = 0;
    for (;;) {
        File f = new File (dir, i++ + ".jar");
        if (!f.exists ()) {
            f.createNewFile();
            return f;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:BuildZipDistributionTest.java

示例6: saveOneWithUrlExistNameInDirectory

import java.io.File; //导入方法依赖的package包/类
@Test
public void saveOneWithUrlExistNameInDirectory() {
    Picture picture = pictures.getFirst();
    Picture secondPicture = new Picture(picture.getPath(), picture.getName(), picture.getFileType());

    service.save(picture, URL);
    service.save(secondPicture, URL);

    assertTrue(picture.equals(service.findOne(picture)));
    assertNull("Error\n(Check your directory, and delete picture with name \"name0\" if exist from last test?)", service.findOne(secondPicture));
    File f = new File(picture.getPath() + picture.getName() + picture.getFileType());
    if (f.exists() && !f.isDirectory())
        service.delete(picture);
    else
        fail("the picture wasn't created");
}
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:17,代码来源:PicturesServiceTest.java

示例7: generateSaveFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Creates a filename (where the file should be saved) from info about a
 * download.
 */
public String generateSaveFile(String filename, long filesize)
        throws GenerateSaveFileError {
    String path = generateTempSaveFileName(filename);
    File expPath = new File(path);
    if (!Helpers.isExternalMediaMounted()) {
        Log.d(Constants.TAG, "External media not mounted: " + path);
        throw new GenerateSaveFileError(STATUS_DEVICE_NOT_FOUND_ERROR,
                "external media is not yet mounted");

    }
    if (expPath.exists()) {
        Log.d(Constants.TAG, "File already exists: " + path);
        throw new GenerateSaveFileError(STATUS_FILE_ALREADY_EXISTS_ERROR,
                "requested destination file already exists");
    }
    if (Helpers.getAvailableBytes(Helpers.getFilesystemRoot(path)) < filesize) {
        throw new GenerateSaveFileError(STATUS_INSUFFICIENT_SPACE_ERROR,
                "insufficient space on external storage");
    }
    return path;
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:26,代码来源:DownloaderService.java

示例8: delete

import java.io.File; //导入方法依赖的package包/类
/**
 * delete a file
 *
 * @param file
 */
public static void delete(File file) {
    if (file != null && file.exists()) {
        if (file.isDirectory()) {
            File[] children = file.listFiles();
            if (children != null) {
                for (File child : children) {
                    delete(child);
                }
            }
            file.delete();
        } else {
            file.delete();
        }
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:21,代码来源:FileUtil.java

示例9: createDiskFile

import java.io.File; //导入方法依赖的package包/类
protected void createDiskFile(MultipartElement element) {
    File tempFile = element.getFile();
    if (tempFile.exists()) {
        DiskFile theFile = new DiskFile(tempFile.getAbsolutePath());
        theFile.setContentType(element.getContentType());
        theFile.setFileName(element.getFileName());
        theFile.setFileSize((int) tempFile.length());
        fileElements.put(element.getName(), theFile);
        allElements.put(element.getName(), theFile);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:DiskMultipartRequestHandler.java

示例10: create

import java.io.File; //导入方法依赖的package包/类
public static Builder create(Context context) {
    File file = new File(context.getExternalFilesDir("").getParentFile(), "cache");
    if (file != null && !file.exists()) {
        file.mkdirs();
    }
    UpdateUtil.log("===>>> " + context.getExternalCacheDir());
    return new Builder(context).setWifiOnly(sIsWifiOnly);
}
 
开发者ID:zhanghangyes,项目名称:updateUtils,代码行数:9,代码来源:UpdateManager.java

示例11: upZipFile

import java.io.File; //导入方法依赖的package包/类
/**
 * 解压缩一个文件
 *
 * @param zipFile    压缩文件
 * @param folderPath 解压缩的目标目录
 * @throws IOException 当解压缩过程出错时抛出
 */
public static void upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
    File desDir = new File(folderPath);
    if (!desDir.exists()) {
        desDir.mkdirs();
    }
    ZipFile zf = new ZipFile(zipFile);
    for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = ((ZipEntry) entries.nextElement());
        InputStream in = zf.getInputStream(entry);
        String str = folderPath + File.separator + entry.getName();
        str = new String(str.getBytes("8859_1"), "GB2312");
        File desFile = new File(str);
        if (!desFile.exists()) {
            File fileParentDir = desFile.getParentFile();
            if (!fileParentDir.exists()) {
                fileParentDir.mkdirs();
            }
            desFile.createNewFile();
        }
        OutputStream out = new FileOutputStream(desFile);
        byte buffer[] = new byte[BUFF_SIZE];
        int realLength;
        while ((realLength = in.read(buffer)) > 0) {
            out.write(buffer, 0, realLength);
        }
        in.close();
        out.close();
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:37,代码来源:ZipUtils.java

示例12: writeFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Writes a String to a file. It also adds a note for the user,
 *
 * @param file The file to write to. Cannot be null.
 * @param lines The lines to write.
 * @throws IOException If something did not work :(
 */
private void writeFile(File file, String... lines) throws IOException {
    if (!file.exists()) {
        file.createNewFile();
    }
    try (
            FileWriter fileWriter = new FileWriter(file);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)
    ) {
        for (String line : lines) {
            bufferedWriter.write(line);
            bufferedWriter.newLine();
        }
    }
}
 
开发者ID:shawlaf,项目名称:Banmanager,代码行数:22,代码来源:Metrics.java

示例13: LocalSyncableOutputStream

import java.io.File; //导入方法依赖的package包/类
public LocalSyncableOutputStream(Path path) throws FileNotFoundException {
  File dir = new File(path.getParent().toString());
  if (!dir.exists()) {
    boolean success = dir.mkdirs();
    if (!success) {
      throw new FileNotFoundException("failed to create parent directory");
    }
  }
  fos = new FileOutputStream(path.toString());
  output = new BufferedOutputStream(fos, 64*1024);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:12,代码来源:LocalSyncableFileSystem.java

示例14: start

import java.io.File; //导入方法依赖的package包/类
@Override
public Object start(final IApplicationContext context) throws Exception {
	Object o = context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
	Display.getDefault();
	if (o != null && o instanceof String[]) {
		String[] args = (String[]) o;
		for (int i = 0; i < args.length; i++) {
			if (args[i].equals(DESTINATION_ARG)) {
				m_directory = new File(args[i + 1]);
			} else if (args[i].equals(CATEGORY_ARG)) {
				m_catPath = args[i + 1];
			} else if (args[i].equals(PLUGIN_ARG)) {
				m_pluginIds.add(args[i + 1]);
			} else if (args[i].equals(INCLUDE_DEPRECATED_ARG)) {
				m_includeDeprecated = true;
			} else if (args[i].equals("-help")) {
				printUsage();
				return EXIT_OK;
			}
		}
	}

	if (m_directory == null) {
		System.err.println("No output directory specified");
		printUsage();
		return 1;
	} else if (!m_directory.exists() && !m_directory.mkdirs()) {
		System.err.println("Could not create output directory '" + m_directory.getAbsolutePath() + "'.");
		return 1;
	}

	generate();

	return EXIT_OK;
}
 
开发者ID:qqilihq,项目名称:knime-json-node-doc-generator,代码行数:36,代码来源:JsonNodeDocuGenerator.java

示例15: copyTestFile

import java.io.File; //导入方法依赖的package包/类
/**
 * Copies a file from assets to the device's file system.
 * @param context
 * @param srcFilePath the source file path in assets.
 * @param destFilePath the destination file path.
 * @throws IllegalStateException if the destination file already exists.
 */
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
private static void copyTestFile(Context context, String srcFilePath, String destFilePath)
        throws IOException {
    File destFile = new File(destFilePath);
    if (destFile.exists()) {
        throw new IllegalStateException(srcFilePath + " already exists.");
    }

    if (!FileUtils.extractAsset(context, srcFilePath, destFile)) {
        throw new IOException("Could not extract asset " + srcFilePath + ".");
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:20,代码来源:TestFilesInstaller.java


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