Example usage for java.io File delete

List of usage examples for java.io File delete

Introduction

In this page you can find the example usage for java.io File delete.

Prototype

public boolean delete() 

Source Link

Document

Deletes the file or directory denoted by this abstract pathname.

Usage

From source file:actors.ConfigUtil.java

static void deletePropertiesFile(long whEtlExecId, String outDir) {
    File configFile = new File(outDir, whEtlExecId + ".properties");
    if (configFile.exists()) {
        configFile.delete();
    }/* www  . j  av a2  s. com*/
}

From source file:com.fileOperations.WordToPDF.java

/**
 * Creates PDF from DOCX, does this by opening file and "SaveAs" within
 * Microsoft Office itself and closing out.
 *
 * @param filePath String/*ww  w .  j a va 2s  .  c o m*/
 * @param fileName String
 * @return String - new File Name
 */
public static String createPDF(String filePath, String fileName) {
    ActiveXComponent eolWord = null;
    String docxFile = filePath + fileName;
    String pdfFile = filePath + FilenameUtils.removeExtension(fileName) + ".pdf";

    File attachmentLocation = new File(filePath);
    if (!attachmentLocation.exists()) {
        attachmentLocation.mkdirs();
    }

    eolWord = JacobCOMBridge.setWordActive(true, false, eolWord);
    if (eolWord != null) {
        try {
            //Open MS Word & Save AS
            Dispatch document = eolWord.getProperty("Documents").toDispatch();
            Dispatch.call(document, "Open", docxFile).toDispatch();
            Dispatch WordBasic = Dispatch.call(eolWord, "WordBasic").getDispatch();
            Dispatch.call(WordBasic, "FileSaveAs", pdfFile, new Variant(17));
            Dispatch.call(document, "Close", new Variant(false));
            Thread.sleep(250);

            //Close out MS Word
            JacobCOMBridge.setWordActive(false, false, eolWord);
            Dispatch.call(eolWord, "Quit");
            eolWord.safeRelease();
            File oldDoc = new File(docxFile);
            oldDoc.delete();
            return FilenameUtils.getName(pdfFile);
        } catch (InterruptedException ex) {
            ExceptionHandler.Handle(ex);
            return "";
        }
    }
    return "";
}

From source file:Main.java

public static void deleteDir(File file) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            deleteDir(f);//from w  ww .j  ava  2s. c  om
        }
    }

    file.delete();
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles())
            deleteRecursive(child);//  ww  w.  j  a v  a 2  s  .c  o  m

    fileOrDirectory.delete();
}

From source file:it.restrung.rest.utils.IOUtils.java

/**
 * Serializes ans saves a Serializable object to a file
 *
 * @param object the source object/*from www  .  j  a  va 2  s . c  o m*/
 * @param file   the target file
 */
static public void saveSerializableObjectToDisk(Object object, File file) {
    try {
        file.delete();
        file.createNewFile();
        FileOutputStream fos = new FileOutputStream(file);
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        ObjectOutputStream out = new ObjectOutputStream(gzos);
        out.writeObject(object);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        Log.d(IOUtils.class.getName(), "Error, file not found for save serializable object to disk");
        throw new RuntimeException(e);
    } catch (IOException e) {
        Log.d(IOUtils.class.getName(), "Error on save serializable object");
        throw new RuntimeException(e);
    }
}

From source file:Main.java

synchronized public static int clearFolder(File path) {
    int deletedItems = 0;
    File[] fileList = path.listFiles();
    if (fileList != null) {
        for (File file : fileList) {
            if (file.isDirectory()) {
                deletedItems += clearFolder(file);
            }/*w w  w .  j a  v a 2s.  c  o m*/
            if (file.delete()) {
                deletedItems++;
            }
        }
    }
    return deletedItems;
}

From source file:org.cloudfoundry.tools.io.local.LocalFolder.java

/**
 * Create a temporary folder./*from ww  w. j av a 2s.  c om*/
 * @param prefix the folder prefix
 * @param suffix the folder suffix
 * @return a new temporary folder
 */
public static LocalFolder createTempFolder(String prefix, String suffix) {
    LocalFolder tempFolder;
    try {
        File tempFile = File.createTempFile(prefix, suffix);
        tempFile.delete();
        tempFile.mkdir();
        tempFolder = new LocalFolder(tempFile);
        tempFolder.createIfMissing();
        return tempFolder;
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}

From source file:com.networknt.audit.ServerInfoDisabledTest.java

@AfterClass
public static void tearDown() throws Exception {
    if (server != null) {
        try {//  www  .  j a  v  a  2  s. c o m
            Thread.sleep(100);
        } catch (InterruptedException ie) {

        }
        server.stop();
        logger.info("The server is stopped.");
    }
    // Remove the test.json from home directory
    File configFile = new File(homeDir + "/info.json");
    configFile.delete();
    // this is very important as it impacts subsequent test case if it is not cleared.
    Config.getInstance().clear();
}

From source file:com.networknt.info.ServerInfoDisabledTest.java

@AfterClass
public static void tearDown() throws Exception {
    if (server != null) {
        try {/*from w  w w  .j  a v  a  2 s.  co m*/
            Thread.sleep(100);
        } catch (InterruptedException ignored) {

        }
        server.stop();
        logger.info("The server is stopped.");
    }
    // Remove the test.json from home directory
    File configFile = new File(homeDir + "/info.json");
    configFile.delete();
    // this is very important as it impacts subsequent test case if it is not cleared.
    Config.getInstance().clear();
}

From source file:Main.java

public static void deleteRecyle(File file) {
    if (file.isDirectory()) {
        for (File childFile : file.listFiles()) {
            deleteRecyle(childFile);//from w  ww . j  av a2  s . co  m
        }
    }
    file.delete();
}