Here you can find the source of emptyFile(final String urlFile)
Parameter | Description |
---|---|
urlFile | The url file. |
Parameter | Description |
---|---|
IOException | if the file does not exist or cannot be read. |
public static void emptyFile(final String urlFile) throws IOException
//package com.java2s; /*/*from w w w. j a va2 s . c om*/ * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2008 - 2009, Geomatys * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import java.io.File; import java.io.IOException; public class Main { /** * Empty a file. * * @param urlFile The url file. * * @throws IOException if the file does not exist or cannot be read. */ public static void emptyFile(final String urlFile) throws IOException { final File file = new File(urlFile); if (file.exists()) { if (!file.delete()) { throw new IOException("Failed to delete file : " + file); } } if (!file.createNewFile()) { //should have been deleted before, so we expect this to be true. throw new IOException("Failed to create file : " + file); } } }