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


Java Files.deleteIfExists方法代码示例

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


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

示例1: testReadAllBytesOnCustomFS

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Exercise Files.readAllBytes(Path) on custom file system. This is special
 * because readAllBytes was originally implemented to use FileChannel
 * and so may not be supported by custom file system providers.
 */
public void testReadAllBytesOnCustomFS() throws IOException {
    Path myfile = PassThroughFileSystem.create().getPath("myfile");
    try {
        int size = 0;
        while (size <= 1024) {
            byte[] b1 = genBytes(size);
            Files.write(myfile, b1);
            byte[] b2 = Files.readAllBytes(myfile);
            assertTrue(Arrays.equals(b1, b2), "bytes not equal");
            size += 512;
        }
    } finally {
        Files.deleteIfExists(myfile);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:BytesAndLines.java

示例2: clearCache

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Clear this ReactiveJournal's {@link #getDir() data directory} from ReactiveJournal-specific binary files, and remove it as
 * well (but only if it has become empty). If other files have been created inside the data directory, it is the
 * responsibility of the user to delete them AND the data directory.
 *
 * @throws IOException in case of directory traversal or file deletion problems
 */
public void clearCache() throws IOException {
    LOG.info("Deleting existing recording [{}]", dir);
    Path journalDir = Paths.get(dir);
    if(Files.exists(journalDir)) {
        Files.walk(journalDir)
                .map(Path::toFile)
                .filter(f -> f.isFile() && f.getName().endsWith(".cq4"))
                .peek(f -> LOG.info("Removing {}", f.getName()))
                .forEach(File::delete);

        try {
            Files.deleteIfExists(journalDir);
        } catch (DirectoryNotEmptyException e) {
            LOG.info("Directory does not only contain cq4 files, not deleted");
        }
    }
}
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:25,代码来源:ReactiveJournal.java

示例3: deleteTaskFiles

import java.nio.file.Files; //导入方法依赖的package包/类
public static void deleteTaskFiles(String taskId, boolean deleteUploadPath) {
    try {
        Path downPath = getDownloadPath(taskId);
        Files.deleteIfExists(downPath);

        if (deleteUploadPath) {
            Files.deleteIfExists(getUploadPath(taskId));
        }

        Files.deleteIfExists(getMetaDataPath(taskId));
        Files.deleteIfExists(getMd5DataPath(taskId));

    } catch (Exception e) {
        logger.error("delete files error for taskId:{}", taskId, e);
    }
}
 
开发者ID:alibaba,项目名称:Dragonfly,代码行数:17,代码来源:PathUtil.java

示例4: emptyLogsFolder

import java.nio.file.Files; //导入方法依赖的package包/类
private void emptyLogsFolder() throws IOException {
    logsFolder = new File("./javares/logs");
    if (!logsFolder.exists()) {
        logsFolder.mkdirs();
    } else {
        for (File file : logsFolder.listFiles()) {
            Files.deleteIfExists(file.toPath());
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:11,代码来源:LoggerInitListenerTest.java

示例5: removeFilesAndEmptyDirs

import java.nio.file.Files; //导入方法依赖的package包/类
private void removeFilesAndEmptyDirs(List<String> dirsToRetry, Map.Entry<String, String> k) {
    try {
        Files.deleteIfExists(Paths.get(PATH + SEPARATOR + k.getKey()));
    } catch (IOException e) {
        if(e instanceof DirectoryNotEmptyException) {
            dirsToRetry.add(k.getKey());
        } else {
            e.printStackTrace();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:12,代码来源:ArchiveUtilTest.java

示例6: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        storeType = args[0];
        Files.deleteIfExists(Paths.get("dup.ks"));

        // Create chain: root -> int -> me
        run("-genkeypair -alias me -dname CN=Me");
        run("-genkeypair -alias int -dname CN=Int");
        run("-genkeypair -alias root -dname CN=Root");

        run("-certreq -alias int -file int.req");
        run("-gencert -infile int.req -alias root -rfc -outfile int.resp");
        run("-importcert -file int.resp -alias int");

        run("-certreq -alias me -file me.req");
        run("-gencert -infile me.req -alias int -rfc -outfile me.resp");
        run("-importcert -file me.resp -alias me");

        // Export certs
        run("-exportcert -alias me -file me -rfc");
        run("-exportcert -alias int -file int -rfc");
        run("-exportcert -alias root -file root -rfc");

        // test 1: just the 3 certs
        test("me", "int", "root");

        // test 2: 3 chains (without root) concatenated
        test("me", "int", "int", "root");

        // test 3: 3 full chains concatenated
        test("me", "int", "root", "int", "root", "root");

        // test 4: a mess
        test("root", "me", "int", "int", "me", "me", "root", "int");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:DupImport.java

示例7: clean

import java.nio.file.Files; //导入方法依赖的package包/类
public static void clean(String name) {
    try {
        Path path = getPathToObject(name);
        Files.deleteIfExists(path);
    } catch (URISyntaxException | IOException e) {
        Log.log(Log.LOG_DEBUG, "Error while clean parser!", e); //$NON-NLS-1$
    }
}
 
开发者ID:pgcodekeeper,项目名称:pgcodekeeper,代码行数:9,代码来源:PgDbParser.java

示例8: testWriteFile

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void testWriteFile() throws IOException {
	List<Sequence> sequences = new ArrayList<>();
	sequences.add(new Sequence(
		"seq1", "AV---GTACGTACGTACGTCATGCATGCATGCATGTAGCTAGCTAGCTAGC..."));
	sequences.add(new Sequence(
		"seq2-cc.z", "ACGTACGTACGAACGTCATGCATCCATGCATGTAGCTAGCTAGCTAGC"));
	sequences.add(new Sequence(
		"seq3", "RMRHARMSSDVN"));
	String testFilePath = "/tmp/fastaUtilsWriteFile.fasta";
	FastaUtils.writeFile(sequences, testFilePath);
	String result = new String(Files.readAllBytes(Paths.get(testFilePath)));
	String expecteds =
		">seq1\n" +
		"AVGTACGTACGTACGTCATGCATGCATGCATGTAGCTAGCTAGCTAGC\n" +
		">seq2-cc.z\n" +
		"ACGTACGTACGAACGTCATGCATCCATGCATGTAGCTAGCTAGCTAGC\n" +
		">seq3\n" +
		"RMRHARMSSDVN\n";
	assertEquals(expecteds, result);
	Files.deleteIfExists(Paths.get(testFilePath));

	FastaUtils.writeFile(sequences.get(0), testFilePath);
	result = new String(Files.readAllBytes(Paths.get(testFilePath)));
	expecteds =
		">seq1\n" +
		"AVGTACGTACGTACGTCATGCATGCATGCATGTAGCTAGCTAGCTAGC\n";
	assertEquals(expecteds, result);
	Files.deleteIfExists(Paths.get(testFilePath));
}
 
开发者ID:hivdb,项目名称:sierra,代码行数:31,代码来源:FastaUtilsTest.java

示例9: deleteAll

import java.nio.file.Files; //导入方法依赖的package包/类
private static void deleteAll(int v, ArrayList<String> createdFiles)
throws IOException{
    /*
    v=0 elimina tutto
    v=1 lascia i .asm
    v=2 lascia i .o
    */
    for(String t:createdFiles){
        if(v!=1)
            Files.deleteIfExists(Paths.get(t+".asm"));
        if(v!=2)
            Files.deleteIfExists(Paths.get(t+".o"));
    }
}
 
开发者ID:Loara,项目名称:Meucci,代码行数:15,代码来源:Master.java

示例10: deleteLogFile

import java.nio.file.Files; //导入方法依赖的package包/类
static void deleteLogFile(String fileName) {
    try {
        Files.deleteIfExists(Paths.get(fileName));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ripreal,项目名称:V8LogScanner,代码行数:8,代码来源:V8LogFileConstructor.java

示例11: deleteByRuleFilename

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void deleteByRuleFilename(String ruleFilename,String filePath) {
    try {
        System.out.println(Paths.get(filePath).resolve(ruleFilename));
        Files.deleteIfExists(Paths.get(filePath).resolve(ruleFilename));
    } catch (IOException e) {
        e.printStackTrace();
    }
    documentRepository.deleteByRuleFilename(ruleFilename);
}
 
开发者ID:realxujiang,项目名称:itweet-boot,代码行数:11,代码来源:StorageServiceImpl.java

示例12: test7029048

import java.nio.file.Files; //导入方法依赖的package包/类
static void test7029048() throws IOException {
    String desc = null;
    for (LLP_VAR v : LLP_VAR.values()) {
        switch (v) {
            case LLP_SET_WITH_JVM:
                // copy the files into the directory structures
                copyFile(srcLibjvmSo, dstServerLibjvm);
                // does not matter if it is client or a server
                copyFile(srcLibjvmSo, dstClientLibjvm);
                desc = "LD_LIBRARY_PATH should be set";
                break;
            case LLP_SET_EMPTY_PATH:
                if (!dstClientDir.exists()) {
                    Files.createDirectories(dstClientDir.toPath());
                } else {
                    Files.deleteIfExists(dstClientLibjvm.toPath());
                }

                if (!dstServerDir.exists()) {
                    Files.createDirectories(dstServerDir.toPath());
                } else {
                    Files.deleteIfExists(dstServerLibjvm.toPath());
                }

                desc = "LD_LIBRARY_PATH should not be set";
                break;
            case LLP_SET_NON_EXISTENT_PATH:
                if (dstLibDir.exists()) {
                    recursiveDelete(dstLibDir);
                }
                desc = "LD_LIBRARY_PATH should not be set";
                break;
            default:
                throw new RuntimeException("unknown case");
        }

        /*
         * Case 1: set the server path
         */
        env.clear();
        env.put(LD_LIBRARY_PATH, dstServerDir.getAbsolutePath());
        run(env, v.value + 1, "Case 1: " + desc);

        /*
         * Case 2: repeat with client path
         */
        env.clear();
        env.put(LD_LIBRARY_PATH, dstClientDir.getAbsolutePath());
        run(env, v.value + 1, "Case 2: " + desc);

        if (isSolaris) {
            /*
             * Case 3: set the appropriate LLP_XX flag,
             * java64 -d64, LLP_64 is relevant, LLP_32 is ignored
             */
            env.clear();
            env.put(LD_LIBRARY_PATH_64, dstServerDir.getAbsolutePath());
            run(env, v.value + 1, "Case 3: " + desc);
        }
    }
    return;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:63,代码来源:Test7029048.java

示例13: close

import java.nio.file.Files; //导入方法依赖的package包/类
@AfterClass
public void close() throws IOException {
    Files.deleteIfExists(output);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:ControlCharTest.java

示例14: testPostUpdate_existingSslClusterUpdateKeyStore

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Test updating existing ssl cluster, updating the KeyStore file only.
 * This should leave the truststore file/password as is.
 */
@Test
@Transactional
public void testPostUpdate_existingSslClusterUpdateKeyStore() throws Exception {
    // Create an existing cluster
    final Cluster originalCluster = clusterTestTools.createCluster("My New Cluster");
    originalCluster.setValid(true);
    originalCluster.setSslEnabled(true);
    originalCluster.setKeyStorePassword("DummyKeyStorePassword");
    originalCluster.setKeyStoreFile("Cluster.KeyStore.jks");
    originalCluster.setTrustStorePassword("DummyTrustStorePassword");
    originalCluster.setTrustStoreFile("Cluster.TrustStore.jks");
    clusterRepository.save(originalCluster);

    // Create dummy JKS files
    FileTestTools.createDummyFile(keyStoreUploadPath + originalCluster.getKeyStoreFile(), "KeyStoreFile");
    FileTestTools.createDummyFile(keyStoreUploadPath + originalCluster.getTrustStoreFile(), "TrustStoreFile");

    // Only update cluster name, brokers, keep SSL enabled, and KeyStore file + password
    final String expectedClusterName = "UpdatedClusterName" + System.currentTimeMillis();
    final String expectedBrokerHosts = "updatedHost:9092";

    final MockMultipartFile keyStoreUpload = new MockMultipartFile("keyStoreFile", "UpdatedKeyStoreFile".getBytes(Charsets.UTF_8));

    // Hit create page.
    mockMvc
        .perform(fileUpload("/configuration/cluster/update")
            .file(keyStoreUpload)
            .with(user(adminUserDetails))
            .with(csrf())
            .param("id", String.valueOf(originalCluster.getId()))
            .param("name", expectedClusterName)
            .param("brokerHosts", expectedBrokerHosts)
            .param("ssl", "true")
            .param("keyStorePassword", "NewPassword")
        )
        .andDo(print())
        .andExpect(status().is3xxRedirection())
        .andExpect(redirectedUrl("/configuration/cluster"));

    // Lookup Cluster
    final Cluster cluster = clusterRepository.findOne(originalCluster.getId());
    assertNotNull("Should have new cluster", cluster);
    assertEquals("Has correct name", expectedClusterName, cluster.getName());
    assertEquals("Has correct brokerHosts", expectedBrokerHosts, cluster.getBrokerHosts());
    assertEquals("Should be ssl enabled", true, cluster.isSslEnabled());
    assertEquals("Should not be valid by default", false, cluster.isValid());
    assertEquals("Password should be unchanged", "DummyTrustStorePassword", cluster.getTrustStorePassword());
    assertEquals("Should have trust store file path", "Cluster.TrustStore.jks", cluster.getTrustStoreFile());

    // trust store should remain
    final boolean doesTruststoreFileExist = Files.exists(Paths.get(keyStoreUploadPath, cluster.getTrustStoreFile()));
    assertTrue("TrustStore file should have been left untouched", doesTruststoreFileExist);
    final String trustStoreContents = FileTestTools.readFile(keyStoreUploadPath + cluster.getTrustStoreFile());
    assertEquals("TrustStore file should have remained untouched", "TrustStoreFile", trustStoreContents);

    // KeyStore was updated
    assertNotEquals("Password should be changed", "DummyKeyStorePassword", cluster.getKeyStorePassword());
    assertEquals("Should have key store file path", expectedClusterName + ".keystore.jks", cluster.getKeyStoreFile());

    final boolean doesKeyStoreFileExist = Files.exists(Paths.get(keyStoreUploadPath, cluster.getKeyStoreFile()));
    assertTrue("keyStore file should exist", doesKeyStoreFileExist);
    final String keyStoreContents = FileTestTools.readFile(keyStoreUploadPath + cluster.getKeyStoreFile());
    assertEquals("KeyStore file should have been updated", "UpdatedKeyStoreFile", keyStoreContents);

    // Cleanup
    Files.deleteIfExists(Paths.get(keyStoreUploadPath, cluster.getTrustStoreFile()));
    Files.deleteIfExists(Paths.get(keyStoreUploadPath, cluster.getKeyStoreFile()));
}
 
开发者ID:SourceLabOrg,项目名称:kafka-webview,代码行数:73,代码来源:ClusterConfigControllerTest.java

示例15: setUp

import java.nio.file.Files; //导入方法依赖的package包/类
@Before
public void setUp () throws URISyntaxException, IOException {
    String path = getCurrentPath();
    Files.deleteIfExists(Paths.get(path  + TMP_FILE));
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:6,代码来源:FilesPathHelperTest.java


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