Java Folder Delete emptyFile(String srcFilename)

Here you can find the source of emptyFile(String srcFilename)

Description

empty File

License

Open Source License

Declaration

public static void emptyFile(String srcFilename) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    public static void emptyFile(String srcFilename) throws IOException {
        File srcFile = new File(srcFilename);
        if (!srcFile.exists()) {
            throw new FileNotFoundException("Cannot find the file: " + srcFile.getAbsolutePath());
        }//from w  ww.  j av a2  s .c  om
        if (!srcFile.canWrite()) {
            throw new IOException("Cannot write the file: " + srcFile.getAbsolutePath());
        }
        FileOutputStream outputStream = new FileOutputStream(srcFilename);
        outputStream.close();
    }
}

Related

  1. clearFolderContent(String folderName)
  2. deepDelete(final File file)
  3. emptyAndDelete(File fileOrDir)
  4. emptyDerbyTestDirectory(final String derbyTestDirectory)
  5. emptyFile(final String urlFile)
  6. emptyFolder(File dir)
  7. emptyFolder(File folder)
  8. emptyFolder(File folder)
  9. emptyFolder(File folder, boolean ignoreCannotDel)