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


Java Files.delete方法代码示例

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


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

示例1: removeImage

import java.nio.file.Files; //导入方法依赖的package包/类
public boolean removeImage(ImageFile imageFile) {
    int answ = JOptionPane.showConfirmDialog(frame, "Are you sure to remove the image \""+imageFile.getName()+"\"", "Remove an image", JOptionPane.YES_NO_OPTION);
    if (answ == JOptionPane.YES_OPTION)
    {
        try 
        {
            Files.delete(imageFile.toPath());
            refresh(new Change(null, -1, "delete.image", imageFile, null));
            return true;
        } 
        catch (IOException ex) 
        {
            ex.printStackTrace();
            return false;
        }

    }
    return false;
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:20,代码来源:Project.java

示例2: fileFinderTest

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void fileFinderTest() {
	try {
		Files.write(Paths.get(System.getProperty("java.io.tmpdir")+"/test.xml")
			, Arrays.asList("Test"), Charset.forName("UTF-8"));		
		InputStream file = new Filefinder().find("test");			
		
		BufferedReader r = new BufferedReader(new InputStreamReader(file, StandardCharsets.UTF_8));
		String str = null; 
		str = r.readLine();
		
		assertEquals("Test", str);
		Files.delete(Paths.get(System.getProperty("java.io.tmpdir")+"/test.xml"));

		
		
	} catch (Exception e) {
		e.printStackTrace();
		try {
			Files.delete(Paths.get(System.getProperty("java.io.tmpdir")+"/test.xml"));
		} catch (IOException e1) {}
		fail();
	}
}
 
开发者ID:danicuestasuarez,项目名称:NMapGUI,代码行数:25,代码来源:NMapGuiUtilTests.java

示例3: testClustersMkvIdAndOffset

import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void testClustersMkvIdAndOffset() throws IOException, MkvElementVisitException {
    InputStreamParserByteSource parserByteSource = getClustersByteSource();

    StreamingMkvReader streamReader = StreamingMkvReader.createDefault(parserByteSource);

    Path tempOutputFile = Files.createTempFile("StreamingMkvClusters","offset.txt");
    try (BufferedWriter writer = Files.newBufferedWriter(tempOutputFile,
            StandardCharsets.US_ASCII,
            StandardOpenOption.WRITE,
            StandardOpenOption.CREATE)) {
        ElementSizeAndOffsetVisitor offsetVisitor = new ElementSizeAndOffsetVisitor(writer);
        while (streamReader.mightHaveNext()) {
            Optional<MkvElement> mkvElement = streamReader.nextIfAvailable();
            if (mkvElement.isPresent()) {
                mkvElement.get().accept(offsetVisitor);
            }
        }
    } finally {
        //Comment this out if the test fails and you need the partial output
        Files.delete(tempOutputFile);
    }
}
 
开发者ID:aws,项目名称:amazon-kinesis-video-streams-parser-library,代码行数:24,代码来源:StreamingMkvReaderTest.java

示例4: createLargeFile

import java.nio.file.Files; //导入方法依赖的package包/类
private static void createLargeFile(long filesize,
                                    File file) throws Exception {
    // Recreate a large file as a sparse file if possible
    Files.delete(file.toPath());

    try (FileChannel fc =
         FileChannel.open(file.toPath(),
                          CREATE_NEW, WRITE, SPARSE)) {
        ByteBuffer bb = ByteBuffer.allocate(1).put((byte)1);
        bb.rewind();
        int rc = fc.write(bb, filesize - 1);

        if (rc != 1) {
            throw new RuntimeException("Failed to write 1 byte"
                                       + " to the large file");
        }
    }
    return;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:LargeFileAvailable.java

示例5: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // create a zip file, and read it in as a byte array
    Path path = Files.createTempFile("bad", ".zip");
    try (OutputStream os = Files.newOutputStream(path);
            ZipOutputStream zos = new ZipOutputStream(os)) {
        ZipEntry e = new ZipEntry("x");
        zos.putNextEntry(e);
        zos.write((int) 'x');
    }
    int len = (int) Files.size(path);
    byte[] data = new byte[len];
    try (InputStream is = Files.newInputStream(path)) {
        is.read(data);
    }
    Files.delete(path);

    // year, month, day are zero
    testDate(data.clone(), 0, LocalDate.of(1979, 11, 30));
    // only year is zero
    testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ZeroDate.java

示例6: terminate

import java.nio.file.Files; //导入方法依赖的package包/类
public void terminate() {
    try {
        System.out.println("Terminating " + mainArgsIdentifier);
        // File must be created before proceeding,
        // otherwise Java process may loop forever
        // waiting for file to be removed.
        Path path = Paths.get(mainArgsIdentifier);
        while (!Files.exists(path)) {
            takeNap();
        }
        Files.delete(path);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MonitorVmStartTerminate.java

示例7: test

import java.nio.file.Files; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
    try {
        file = File.createTempFile("temp", ".img");
        fos = new FileOutputStream(file);
        final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        writer.setOutput(ios);
        final IIOMetadata data = writer.getDefaultStreamMetadata(null);

        if (writer.canWriteSequence()) {
            writer.prepareWriteSequence(data);
        } else {
            try {
                writer.prepareWriteSequence(data);
                throw new RuntimeException(
                        "UnsupportedOperationException was not thrown");
            } catch (final UnsupportedOperationException ignored) {
            // expected
            }
        }
    } finally {
        writer.dispose();
        if (file != null) {
            if (fos != null) {
                fos.close();
            }
            Files.delete(file.toPath());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CanWriteSequence.java

示例8: verwijderBestandenInFolder

import java.nio.file.Files; //导入方法依赖的package包/类
private void verwijderBestandenInFolder(final Path path, final String postfix) throws IOException {
    if (path.toFile().exists()) {
        final List<Path> paths = Files.list(path)
                .filter(p -> p.getFileName()
                        .toString().endsWith(postfix))
                .collect(Collectors.toList());
        for (Path resultPath : paths) {
            Files.delete(resultPath);
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:12,代码来源:SelectieFileServiceImpl.java

示例9: executeBuildozerCommands

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Given a graph of build rules, some project specific and some external, this method constructs a
 * list of buildozer commands, that are then used to write various BUILD files to disk.
 */
static void executeBuildozerCommands(
    ImmutableGraph<BuildRule> ruleDAG, Path workspace, boolean isDryRun, String buildozerBinary)
    throws IOException, InterruptedException {
  ImmutableList<String> commands = computeBuildozerCommands(ruleDAG);
  if (isDryRun) {
    commands.stream().forEach(command -> System.out.println(command));
    return;
  }

  for (Path buildFileDir : getBuildFilesForBuildozer(ruleDAG, workspace)) {
    generateBuildFileIfNecessary(buildFileDir);
  }
  File tempFile = File.createTempFile("bfgOutput", ".txt");
  try {
    Files.write(tempFile.toPath(), commands, StandardCharsets.US_ASCII);
    ProcessBuilder pb = new ProcessBuilder();
    pb.command(buildozerBinary, "-f", tempFile.toPath().toString(), "-k");
    pb.environment().clear();
    Process p = pb.start();
    if (p.waitFor() != 0) {
      System.err.println("Error from executing buildozer:");
      try (BufferedReader stderr =
          new BufferedReader(new InputStreamReader(p.getErrorStream(), UTF_8))) {
        String line;
        while ((line = stderr.readLine()) != null) {
          System.err.println(line);
        }
      }
    }
  } finally {
    Files.delete(tempFile.toPath());
  }
}
 
开发者ID:bazelbuild,项目名称:BUILD_file_generator,代码行数:38,代码来源:Bfg.java

示例10: delete

import java.nio.file.Files; //导入方法依赖的package包/类
private static void delete(Path path) throws IOException {
	List<Path> file = Files.list(path).collect(toList());
	for (Path t : file) {
		if (Files.isDirectory(t))
			delete(t);
		else
			Files.delete(t);
	}
}
 
开发者ID:ProgramLeague,项目名称:Avalon-Executive,代码行数:10,代码来源:PathUtils.java

示例11: sendContacts

import java.nio.file.Files; //导入方法依赖的package包/类
private void sendContacts() throws IOException, UntrustedIdentityException {
    File contactsFile = Util.createTempFile();

    try {
        try (OutputStream fos = new FileOutputStream(contactsFile)) {
            DeviceContactsOutputStream out = new DeviceContactsOutputStream(fos);
            for (ContactInfo record : contactStore.getContacts()) {
                out.write(new DeviceContact(record.number, Optional.fromNullable(record.name),
                                            createContactAvatarAttachment(record.number), Optional.fromNullable(record.color),
                                            Optional.absent()));
            }
        }

        if (contactsFile.exists() && contactsFile.length() > 0) {
            try (FileInputStream contactsFileStream = new FileInputStream(contactsFile)) {
                SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
                        .withStream(contactsFileStream)
                        .withContentType("application/octet-stream")
                        .withLength(contactsFile.length())
                        .build();

                // TODO: no idea if "false" is right here
                sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, false)));
            }
        }
    } finally {
        try {
            Files.delete(contactsFile.toPath());
        } catch (IOException e) {
            System.out.println("Failed to delete temp file “" + contactsFile + "”: " + e.getMessage());
        }
    }
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:34,代码来源:Manager.java

示例12: testTouch

import java.nio.file.Files; //导入方法依赖的package包/类
public void testTouch() throws IOException {
  Path temp = createTempFile();
  assertTrue(Files.exists(temp));
  Files.delete(temp);
  assertFalse(Files.exists(temp));
  MoreFiles.touch(temp);
  assertTrue(Files.exists(temp));
  MoreFiles.touch(temp);
  assertTrue(Files.exists(temp));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:MoreFilesTest.java

示例13: doDelete

import java.nio.file.Files; //导入方法依赖的package包/类
private void doDelete(Path file)
{
	boolean ok = true;
	try
	{
		LOGGER.debug("Deleting file " + file.toString());
		Files.delete(file);
	}
	catch( Exception io )
	{
		ok = false;
		success = false;
		LOGGER.warn("Failed to delete file " + file.toString(), io);
	}
	if( ok )
	{
		if( callback != null )
		{
			try
			{
				callback.fileProcessed(file, null);
			}
			catch( Exception e )
			{
				LOGGER.error("File callback threw an exception on file " + file.toString(), e);
			}
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:30,代码来源:FileUtils.java

示例14: clear

import java.nio.file.Files; //导入方法依赖的package包/类
@After
public void clear() throws IOException {
    primaryDb.close();
    secondaryDb.close();
    serverDb.close();

    Files.delete(Paths.get(primaryFile));
    Files.delete(Paths.get(secondaryFile));
    Files.delete(Paths.get(serverFile));
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:11,代码来源:BaseSyncTest.java

示例15: loadBackpack

import java.nio.file.Files; //导入方法依赖的package包/类
private static void loadBackpack(Path path) throws IOException {
    Backpack backpack = BackpackSerializer.loadBackpack(path);
    if (backpack == null || backpack.isOverdue()) {
        Files.delete(path);
    } else {
        BACKPACKS.put(backpack.getUniqueId(), backpack);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:9,代码来源:BackpackManager.java


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