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


Java FileUtils.forceDelete方法代码示例

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


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

示例1: createGitHubRepositoryWithContent

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void createGitHubRepositoryWithContent() throws Exception {
    // given
    final String repositoryName = generateRepositoryName();
    Path tempDirectory = Files.createTempDirectory("test");
    Path file = tempDirectory.resolve("README.md");
    Files.write(file, Collections.singletonList("Read me to know more"), Charset.forName("UTF-8"));

    // when
    final GitRepository targetRepo = getGitHubService().createRepository(repositoryName, MY_GITHUB_REPO_DESCRIPTION);
    getGitHubService().push(targetRepo, tempDirectory.toFile());

    // then
    Assert.assertEquals(GitHubTestCredentials.getUsername() + "/" + repositoryName, targetRepo.getFullName());
    URI readmeUri = UriBuilder.fromUri("https://raw.githubusercontent.com/")
            .path(GitHubTestCredentials.getUsername())
            .path(repositoryName)
            .path("/master/README.md").build();
    HttpURLConnection connection = (HttpURLConnection) readmeUri.toURL().openConnection();
    Assert.assertEquals("README.md should have been pushed to the repo", 200, connection.getResponseCode());

    FileUtils.forceDelete(tempDirectory.toFile());
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:24,代码来源:GitHubServiceIT.java

示例2: cleanUpDir

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void cleanUpDir() {
  try {
    LOG.info("Deleting Keytab dir. " + this.getKeyTabDir());
    File keytabDir = new File(this.getKeyTabDir());
    if (keytabDir.exists()) {
      FileUtils.forceDelete(keytabDir);
    }
    File kdcWorkDir = new File(this.kdc_work_dir);
    LOG.info("Deleting KDC temporary dir. " + kdcWorkDir);
    if (kdcWorkDir.exists()) {
      FileUtils.forceDelete(kdcWorkDir);
    }
  } catch (IOException ex) {
    LOG.error("Couldn't delete work dir");
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:KDCQuasiService.java

示例3: addSingleEntryToTar

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void addSingleEntryToTar(byte[] singleEntryContent, String singleEntryName)
        throws IOException
{
    // create new entry; it requires file for some reasons...
    File tmpFile = File.createTempFile("temp", "bin");
    OutputStream os = new FileOutputStream(tmpFile);
    IOUtils.write(singleEntryContent, os);

    TarArchiveEntry tarEntry = new TarArchiveEntry(tmpFile, singleEntryName);
    outputStream.putArchiveEntry(tarEntry);

    // copy streams
    IOUtils.copy(new ByteArrayInputStream(singleEntryContent), outputStream);
    outputStream.closeArchiveEntry();

    // delete the temp file
    FileUtils.forceDelete(tmpFile);
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:CompressedXmiWriter.java

示例4: editCommityInfo

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void editCommityInfo(CommityInfo info, String lastPath) throws IOException {
    //检查图像有没有变化
    if (!(info.getCHeadImg().equals(lastPath))) {
        //删除之前的图
        FileUtils.forceDelete(new File(StaticVar.getToFilePath() + lastPath));
        //存新图
        String fileName = new File(info.getCHeadImg()).getName();
        String filePathStr = "CommitySpace/" + info.getCid() + "/" + fileName;

        File tarNewFile = new File(StaticVar.getToFilePath() + filePathStr);
        FileUtils.writeByteArrayToFile(tarNewFile, info.getCImgObj().getBytes(StaticVar.getDecodeFileSet()));
        info.setCHeadImg(filePathStr);
    }
    commityManageDao.editCommityInfo(info);

}
 
开发者ID:okingjerryo,项目名称:WeiMusicCommunity-server,代码行数:17,代码来源:CommityManageService.java

示例5: readLatestSnapshot

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Reads the Latest Snapshot version from a Meta file, and then deletes it
 *
 * @param dependency The dependency
 * @param metaFile The Meta file
 *
 * @return The version with "SNAPSHOT" replaced with the latest
 */
@SuppressWarnings("WeakerAccess")
public static @NotNull String readLatestSnapshot(@NotNull Dependency dependency, @NotNull File metaFile) {
	try {
		final Element document = readDocument(metaFile);

		Element snapshot = (Element) document.getElementsByTagName("snapshot").item(0);

		final String timestamp   = readTag(snapshot, "timestamp");
		final String buildNumber = readTag(snapshot, "buildNumber");

		final String latestSnapshot = dependency.getVersion().replace("SNAPSHOT", timestamp + "-" + buildNumber);
		DLoader.debug("Latest Snapshot version of " + dependency.getName() + " is " + latestSnapshot);

		FileUtils.forceDelete(metaFile);

		return latestSnapshot;

	} catch (Exception e) {
		DLoader.log(Level.SEVERE, "Failed to load meta for snapshot of  " + dependency);
		e.printStackTrace();
	}

	return "ERROR";
}
 
开发者ID:Sxtanna,项目名称:dependency-loader,代码行数:33,代码来源:Xmls.java

示例6: unpack

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public void unpack(TaskOutputsInternal taskOutputs, InputStream input, TaskOutputOriginReader readOrigin) {
    for (TaskOutputFilePropertySpec propertySpec : taskOutputs.getFileProperties()) {
        CacheableTaskOutputFilePropertySpec property = (CacheableTaskOutputFilePropertySpec) propertySpec;
        File output = property.getOutputFile();
        if (output == null) {
            continue;
        }
        try {
            switch (property.getOutputType()) {
                case DIRECTORY:
                    makeDirectory(output);
                    FileUtils.cleanDirectory(output);
                    break;
                case FILE:
                    if (!makeDirectory(output.getParentFile())) {
                        if (output.exists()) {
                            FileUtils.forceDelete(output);
                        }
                    }
                    break;
                default:
                    throw new AssertionError();
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    delegate.unpack(taskOutputs, input, readOrigin);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:31,代码来源:OutputPreparingTaskOutputPacker.java

示例7: delFileOldest

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void delFileOldest(ProjectFile file) throws IOException {
    //1.查出最老的文件路径
    ProjectFile oldest = projectDao.getOldestFile(file);
    //2.删除当前文件
    FileUtils.forceDelete(new File(StaticVar.getToFilePath() + oldest.getPFPath()));
    //3 数据库删除这个记录
    projectDao.delOldest(oldest);
}
 
开发者ID:okingjerryo,项目名称:WeiMusicCommunity-server,代码行数:9,代码来源:ProjectService.java

示例8: forceDelete

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void forceDelete(File file) {
    try {
        FileUtils.forceDelete(file);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:GFileUtils.java

示例9: delete

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public void delete() {
    close();
    String fullFileName = dirName + File.separator + fileName;
    File file = new File(fullFileName);
    try {
        FileUtils.forceDelete(file);
    } catch (IOException ex) {
        LOG.warn("delete file exception:", ex);
    }
}
 
开发者ID:wenweihu86,项目名称:distmq,代码行数:11,代码来源:Segment.java

示例10: clearCreatedFolders

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void clearCreatedFolders(File root) {
	File[] files = root.listFiles();
	try {
		for (File file : files) {
			if (file.getName().equalsIgnoreCase("output")) {
				FileUtils.deleteDirectory(file);
			}
			if (file.getName().equalsIgnoreCase("4-ComponentImplementations")) {
				File[] child = file.listFiles();
				for (File c : child) {
					if (c.isFile())
						FileUtils.forceDelete(c);
					else {
						File[] gChild = c.listFiles();
						for (File gC : gChild) {
							if (gC.isDirectory())
								FileUtils.deleteDirectory(gC);
							else if (!StringUtils.endsWith(gC.getName(), ".impl.xml"))
								FileUtils.forceDelete(gC);
						}
					}
				}
			}
		}
	} catch (IOException e) {
		System.out.println(e);
	}
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:29,代码来源:GenerationUtils.java

示例11: process

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public FResult<JSONObject> process(UploadRequest request) throws Exception {
  Long commonFileId = null;
  try {
    File temporaryFile = new File(request.getTemporaryFilePath());
    if (temporaryFile == null || !temporaryFile.isFile() || !temporaryFile.exists()) {
      return FResult.newFailure(HttpResponseCode.SERVER_IO_READ, "上传失败");
    }
    String currentFileMd5 = request.getTemporaryFileMd5();
    String fileId = uploadFileReturnFileId(request.getTemporaryFilePath(), request.getSuffix());
    if (StringUtils.isBlank(fileId)) {
      return FResult.newFailure(HttpResponseCode.SERVER_IO_WRITE, "上传文件到FastDFS失败,请检查FastDFS日志");
    }
    long nowTimestamp = System.currentTimeMillis();
    // 要保存的对象
    UploadFile commonFile = new UploadFile();
    commonFile.setFilemd5(currentFileMd5);
    // 保存主文件后,返回住表ID
    log.debug("你可以控制是否要持久化这个文件");
    commonFileId = commonFileService.addUploadFile(nowTimestamp, commonFile, temporaryFile, request, fileId);
    if (commonFileId == null || commonFileId == 0) {
      log.error("insert common_file failed,record:" + JSON.toJSONString(commonFile));
      FileUtils.forceDelete(temporaryFile);
      return FResult.newFailure(HttpResponseCode.SERVER_DB_ERROR, "保存上传记录失败");
    }
    return buildResult(request.getOriginalFilename(), request.getTemporaryFileSize(), request.getTemporaryFileMd5(), commonFile.getUrl(),
        commonFile.getId());
  } catch (Exception uploadException) {
    log.error("普通文件上传过程中发生错误", uploadException);
    return FResult.newFailure(HttpResponseCode.SERVER_ERROR, "文件上传过程中发生错误");
  }
}
 
开发者ID:devpage,项目名称:fastdfs-quickstart,代码行数:34,代码来源:SimpleJsonFileUploadProcessor.java

示例12: testNoNewline

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testNoNewline() throws FileNotFoundException, IOException {

  Map<String, String> headers = new HashMap<String, String>();
  headers.put("header1", "value1");
  headers.put("header2", "value2");

  OutputStream out = new FileOutputStream(testFile);
  Context context = new Context();
  context.put("appendNewline", "false");
  EventSerializer serializer =
      EventSerializerFactory.getInstance("header_and_text", context, out);
  serializer.afterCreate();
  serializer.write(EventBuilder.withBody("event 1\n", Charsets.UTF_8, headers));
  serializer.write(EventBuilder.withBody("event 2\n", Charsets.UTF_8, headers));
  serializer.write(EventBuilder.withBody("event 3\n", Charsets.UTF_8, headers));
  serializer.flush();
  serializer.beforeClose();
  out.flush();
  out.close();

  BufferedReader reader = new BufferedReader(new FileReader(testFile));
  Assert.assertEquals("{header2=value2, header1=value1} event 1", reader.readLine());
  Assert.assertEquals("{header2=value2, header1=value1} event 2", reader.readLine());
  Assert.assertEquals("{header2=value2, header1=value1} event 3", reader.readLine());
  Assert.assertNull(reader.readLine());
  reader.close();

  FileUtils.forceDelete(testFile);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:31,代码来源:TestHeaderAndBodyTextEventSerializer.java

示例13: removeUploadedFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
protected void removeUploadedFile() {
    if (this.file != null && this.file.exists()) {
        try {
            FileUtils.forceDelete(this.file);
        } catch (IOException e) {
            log.error("Deleting ssl certificate file: " + this.file + " failed when upload was cancelled by user.", e);
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:10,代码来源:SslCertificateUploader.java

示例14: createFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private File createFile(String loc, boolean delete) throws IOException {
	File file = new File(loc);
	if (delete && file.exists())
		FileUtils.forceDelete(file);
	file.getParentFile().mkdirs();
	file.createNewFile();
	return file;
}
 
开发者ID:dstl,项目名称:Open_Source_ECOA_Toolset_AS5,代码行数:9,代码来源:ExportCommand.java

示例15: cleanOutputDir

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void cleanOutputDir() throws IOException {
    if(outputDir.exists() && !outputDir.isDirectory()) {
        throw new IllegalStateException(outputDir.getAbsolutePath() + " is not a directory!");
    }

    if(outputDir.exists()) {
        FileUtils.forceDelete(outputDir);
    }
    FileUtils.forceMkdir(outputDir);
}
 
开发者ID:sdadas,项目名称:spring2ts,代码行数:11,代码来源:SourceGen.java


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