當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。