本文整理汇总了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());
}
示例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");
}
}
示例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);
}
示例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);
}
示例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";
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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, "文件上传过程中发生错误");
}
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}