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


Java File.deleteOnExit方法代码示例

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


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

示例1: test

import java.io.File; //导入方法依赖的package包/类
public void test() throws Exception {

        File file = new File("message.xml");
        file.deleteOnExit();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage msg = createMessage(mf);

        // Save the soap message to file
        try (FileOutputStream sentFile = new FileOutputStream(file)) {
            msg.writeTo(sentFile);
        }

        // See if we get the image object back
        try (FileInputStream fin = new FileInputStream(file)) {
            SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);

            newMsg.writeTo(new ByteArrayOutputStream());

            Iterator<?> i = newMsg.getAttachments();
            while (i.hasNext()) {
                AttachmentPart att = (AttachmentPart) i.next();
                Object obj = att.getContent();
                if (!(obj instanceof StreamSource)) {
                    fail("Got incorrect attachment type [" + obj.getClass() + "], " +
                         "expected [javax.xml.transform.stream.StreamSource]");
                }
            }
        }

    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XmlTest.java

示例2: testEncryptFile_filename

import java.io.File; //导入方法依赖的package包/类
@Test
public void testEncryptFile_filename() throws IOException {

    File encryptedFile
            = new File(
                    encryptionService
                            .encryptFile(
                                    plainTextFilename));

    encryptedFile
            .deleteOnExit();

    KmsDecryptionService
            .instance()
            .decryptFile(
                    encryptedFile,
                    decryptedFilename);

    assertEquals(
            SECRET_FILE_CONTENTS,
            new String(
                    Files.readAllBytes(
                            Paths.get(
                                    decryptedFilename))));
}
 
开发者ID:eonian-technologies,项目名称:secrets-locker,代码行数:26,代码来源:KmsEncryptionServiceIT_encryptFile.java

示例3: getResourceAsFile

import java.io.File; //导入方法依赖的package包/类
private File getResourceAsFile(String resourcePath) {
    try {
        InputStream in = getClass().getResourceAsStream(resourcePath);
        if (in == null) {
            return null;
        }

        File tempFile = File.createTempFile(String.valueOf(in.hashCode()), ".tmp");
        tempFile.deleteOnExit();

        try (FileOutputStream out = new FileOutputStream(tempFile)) {
            byte[] buffer = new byte[2048];
            int bytesRead;
            while ((bytesRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
        }
        return tempFile;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:PanagiotisDrakatos,项目名称:Weather-Forecast,代码行数:24,代码来源:GetCurrentRegion.java

示例4: createRequest

import java.io.File; //导入方法依赖的package包/类
private AcquireRequest createRequest() throws IOException {
	final AcquireRequest request = new AcquireRequest();

	final File file = File.createTempFile("acquire_servlet_test", ".nxs");
	System.err.println("Writing to file " + file);
	file.deleteOnExit();
	request.setFilePath(file.getAbsolutePath());

	final MandelbrotModel mandyModel = new MandelbrotModel();
	mandyModel.setName("mandelbrot");
	mandyModel.setRealAxisName("xNex");
	mandyModel.setImaginaryAxisName("yNex");
	mandyModel.setExposureTime(0.01);

	request.setDetectorName(mandyModel.getName());
	request.setDetectorModel(mandyModel);

	return request;
}
 
开发者ID:eclipse,项目名称:scanning,代码行数:20,代码来源:AcquireRequestTest.java

示例5: createTempFile

import java.io.File; //导入方法依赖的package包/类
@Override
public FileObject createTempFile(FileObject parent, String prefix, String suffix, boolean deleteOnExit) throws IOException {
    if (parent.isFolder() && parent.isValid()) {
        File tmpFile = File.createTempFile(prefix, suffix, FileUtil.toFile(parent));
        if (deleteOnExit) {
            tmpFile.deleteOnExit();
        }
        FileObject fo = FileUtil.toFileObject(tmpFile);
        if (fo != null && fo.isData() && fo.isValid()) {
            return fo;
        }
        tmpFile.delete();
    }
    throw new IOException("Cannot create temporary file"); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:FileBasedFileSystem.java

示例6: testReadAndWriteFile

import java.io.File; //导入方法依赖的package包/类
@Test
public void testReadAndWriteFile() throws Exception
{
    ContentWriter writer = getWriter();
    
    File sourceFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
    sourceFile.deleteOnExit();
    // dump some content into the temp file
    String content = "ABC";
    FileOutputStream os = new FileOutputStream(sourceFile);
    os.write(content.getBytes());
    os.flush();
    os.close();
    
    // put our temp file's content
    writer.putContent(sourceFile);
    assertTrue("Stream close not detected", writer.isClosed());
    
    // create a sink temp file
    File sinkFile = TempFileProvider.createTempFile("testReadAndWriteFile", ".txt");
    sinkFile.deleteOnExit();
    
    // get the content into our temp file
    ContentReader reader = writer.getReader();
    reader.getContent(sinkFile);
    
    // read the sink file manually
    FileInputStream is = new FileInputStream(sinkFile);
    byte[] buffer = new byte[100];
    int count = is.read(buffer);
    assertEquals("No content read", 3, count);
    is.close();
    String check = new String(buffer, 0, count);
    
    assertEquals("Write out of and read into files failed", content, check);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:AbstractWritableContentStoreTest.java

示例7: testLocalInfileDisabled

import java.io.File; //导入方法依赖的package包/类
public void testLocalInfileDisabled() throws Exception {
    createTable("testLocalInfileDisabled", "(field1 varchar(255))");

    File infile = File.createTempFile("foo", "txt");
    infile.deleteOnExit();
    //String url = infile.toURL().toExternalForm();
    FileWriter output = new FileWriter(infile);
    output.write("Test");
    output.flush();
    output.close();

    Connection loadConn = getConnectionWithProps(new Properties());

    try {
        // have to do this after connect, otherwise it's the server that's enforcing it
        ((com.mysql.jdbc.Connection) loadConn).setAllowLoadLocalInfile(false);
        try {
            loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled");
            fail("Should've thrown an exception.");
        } catch (SQLException sqlEx) {
            assertEquals(SQLError.SQL_STATE_GENERAL_ERROR, sqlEx.getSQLState());
        }

        assertFalse(loadConn.createStatement().executeQuery("SELECT * FROM testLocalInfileDisabled").next());
    } finally {
        loadConn.close();
    }
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:29,代码来源:ConnectionTest.java

示例8: main

import java.io.File; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    RIFFWriter writer = null;
    RIFFReader reader = null;
    File tempfile = File.createTempFile("test",".riff");
    try
    {
        writer = new RIFFWriter(tempfile, "TEST");
        RIFFWriter chunk = writer.writeChunk("TSCH");
        chunk.writeByte(10);
        writer.close();
        writer = null;
        FileInputStream fis = new FileInputStream(tempfile);
        reader = new RIFFReader(fis);
        RIFFReader readchunk = reader.nextChunk();
        long p = readchunk.getFilePointer();
        readchunk.readByte();
        assertEquals(p+1,readchunk.getFilePointer());
        fis.close();
        reader = null;


    }
    finally
    {
        if(writer != null)
            writer.close();
        if(reader != null)
            reader.close();

        if(tempfile.exists())
            if(!tempfile.delete())
                tempfile.deleteOnExit();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:GetFilePointer.java

示例9: setUp

import java.io.File; //导入方法依赖的package包/类
protected void setUp() throws Exception {
	super.setUp();
	File tempFile = File.createTempFile("settingsTest", ".tmp");
	tempFile.deleteOnExit();
	
	PrintWriter out = new PrintWriter(tempFile);
	
	for (String s : INPUT) {
		out.println(s);
	}
	out.close();
	
	Settings.init(tempFile.getAbsolutePath());
	s = new Settings();
}
 
开发者ID:MaX121,项目名称:Bachelor-Thesis,代码行数:16,代码来源:SettingsTest.java

示例10: delete

import java.io.File; //导入方法依赖的package包/类
/**
 * Deletes a file. If the file is a directory its contents are recursively
 * deleted.
 *
 * @param file File to be deleted.
 */
public static void delete(final File file) {
    if (file.isDirectory()) {
        for (File child: file.listFiles()) {
            delete(child);
        }
    }
    if (!file.delete()) {
        file.deleteOnExit();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Utils.java

示例11: loadLibraryAsResource

import java.io.File; //导入方法依赖的package包/类
/**
 * Search the specified native library in any of the JAR files
 * loaded by this classloader.  If the library is found copy it
 * into the library directory and return the absolute path.  If
 * the library is not found then return null.
 */
private synchronized String loadLibraryAsResource(String libname) {
    try {
        InputStream is = getResourceAsStream(
                libname.replace(File.separatorChar,'/'));
        if (is != null) {
            try {
                File directory = new File(libraryDirectory);
                directory.mkdirs();
                File file = Files.createTempFile(directory.toPath(),
                                                 libname + ".", null)
                                 .toFile();
                file.deleteOnExit();
                FileOutputStream fileOutput = new FileOutputStream(file);
                try {
                    byte[] buf = new byte[4096];
                    int n;
                    while ((n = is.read(buf)) >= 0) {
                       fileOutput.write(buf, 0, n);
                    }
                } finally {
                    fileOutput.close();
                }
                if (file.exists()) {
                    return file.getAbsolutePath();
                }
            } finally {
                is.close();
            }
        }
    } catch (Exception e) {
        MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                "loadLibraryAsResource",
                "Failed to load library : " + libname, e);
        return null;
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:44,代码来源:MLet.java

示例12: testEncryptFile_file

import java.io.File; //导入方法依赖的package包/类
@Test
public void testEncryptFile_file() throws IOException {

    File encryptedFile
            = encryptionService
                    .encryptFile(
                            plainTextFile);

    encryptedFile
            .deleteOnExit();

    KmsDecryptionService
            .instance()
            .decryptFile(
                    encryptedFile,
                    decryptedFilename);

    File decryptedFile
            = new File(decryptedFilename);

    decryptedFile
            .deleteOnExit();

    assertEquals(
            SECRET_FILE_CONTENTS,
            new String(
                    Files.readAllBytes(
                            Paths.get(
                                    decryptedFilename))));
}
 
开发者ID:eonian-technologies,项目名称:secrets-locker,代码行数:31,代码来源:KmsEncryptionServiceIT_encryptFile.java

示例13: benchmarkNexus

import java.io.File; //导入方法依赖的package包/类
private long benchmarkNexus(int imageSize, long max)  throws Exception {

		MandelbrotModel model = new MandelbrotModel();
		model.setName("mandelbrot");
		model.setRealAxisName("xNex");
		model.setImaginaryAxisName("yNex");
		model.setColumns(imageSize);
		model.setRows(imageSize);
		model.setMaxIterations(1);
		model.setExposureTime(0.0);

		IRunnableDevice<MandelbrotModel> detector = dservice.createRunnableDevice(model);

		final BenchmarkBean bean = new BenchmarkBean(256, 5000l, 1, true, detector);
		File output = File.createTempFile("test_mandel_nexus", ".nxs");
		output.deleteOnExit();
		bean.setFilePath(output.getAbsolutePath());

		try {
			benchmarkStep(bean); // set things up

			// Benchmark things. A good idea to do nothing much else on your machine for this...
			long point1     = benchmarkStep(new BenchmarkBean(1, 100, 1, detector, output)); // should take not more than 2ms sleep + scan time

			// should take not more than 64*point1 + scan time
			long point10    = benchmarkStep(new BenchmarkBean(10,    (10*point1)+fudge, max,   10, detector, output));

			// should take not more than 4*point64 sleep + scan time
			long point100   = benchmarkStep(new BenchmarkBean(100,   (10*point10)+fudge, max,  10, detector, output));

			return point100/100;

		} finally {
		    output.delete();
		}
	}
 
开发者ID:eclipse,项目名称:scanning,代码行数:37,代码来源:BenchmarkScanTest.java

示例14: tempfile

import java.io.File; //导入方法依赖的package包/类
private File tempfile(String name, String suffix)
{
    File file = TempFileProvider.createTempFile(name, suffix);
    file.deleteOnExit();
    return file;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:7,代码来源:ContentCacheImplTest.java

示例15: launch

import java.io.File; //导入方法依赖的package包/类
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException,
    InterruptedException, NotBoundException {
  DUNIT_SUSPECT_FILE = new File(SUSPECT_FILENAME);
  DUNIT_SUSPECT_FILE.delete();
  DUNIT_SUSPECT_FILE.deleteOnExit();

  // create an RMI registry and add an object to share our tests config
  int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
  Registry registry = LocateRegistry.createRegistry(namingPort);
  System.setProperty(RMI_PORT_PARAM, "" + namingPort);

  JUnit4DistributedTestCase.initializeBlackboard();

  final ProcessManager processManager = new ProcessManager(namingPort, registry);
  master = new Master(registry, processManager);
  registry.bind(MASTER_PARAM, master);

  // inhibit banners to make logs smaller
  System.setProperty(InternalLocator.INHIBIT_DM_BANNER, "true");

  // restrict membership ports to be outside of AvailablePort's range
  System.setProperty(DistributionConfig.RESTRICT_MEMBERSHIP_PORT_RANGE, "true");

  Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
      // System.out.println("shutting down DUnit JVMs");
      // for (int i=0; i<NUM_VMS; i++) {
      // try {
      // processManager.getStub(i).shutDownVM();
      // } catch (Exception e) {
      // System.out.println("exception shutting down vm_"+i+": " + e);
      // }
      // }
      // // TODO - hasLiveVMs always returns true
      // System.out.print("waiting for JVMs to exit");
      // long giveUp = System.currentTimeMillis() + 5000;
      // while (giveUp > System.currentTimeMillis()) {
      // if (!processManager.hasLiveVMs()) {
      // return;
      // }
      // System.out.print(".");
      // System.out.flush();
      // try {
      // Thread.sleep(1000);
      // } catch (InterruptedException e) {
      // break;
      // }
      // }
      // System.out.println("\nkilling any remaining JVMs");
      processManager.killVMs();
    }
  });

  // Create a VM for the locator
  processManager.launchVM(LOCATOR_VM_NUM);

  // wait for the VM to start up
  if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
    throw new RuntimeException(STARTUP_TIMEOUT_MESSAGE);
  }

  locatorPort = startLocator(registry);

  init(master);

  // Launch an initial set of VMs
  for (int i = 0; i < NUM_VMS; i++) {
    processManager.launchVM(i);
  }

  // wait for the VMS to start up
  if (!processManager.waitForVMs(STARTUP_TIMEOUT)) {
    throw new RuntimeException(STARTUP_TIMEOUT_MESSAGE);
  }

  // populate the Host class with our stubs. The tests use this host class
  DUnitHost host =
      new DUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), processManager);
  host.init(registry, NUM_VMS);

}
 
开发者ID:ampool,项目名称:monarch,代码行数:82,代码来源:DUnitLauncher.java


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