Here you can find the source of createFile(String fileName)
public static final FileOutputStream createFile(String fileName) throws IOException
//package com.java2s; /******************************************************************************* * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*w w w . j a va 2 s. com*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Create a {@link FileOutputStream} corresponding to a particular file name. * Delete the existing file if one exists. */ public static final FileOutputStream createFile(String fileName) throws IOException { if (fileName == null) { throw new IllegalArgumentException("null file"); } File f = new File(fileName); if (f.getParentFile() != null && !f.getParentFile().exists()) { boolean result = f.getParentFile().mkdirs(); if (!result) { throw new IOException("failed to create " + f.getParentFile()); } } if (f.exists()) { f.delete(); } boolean result = f.createNewFile(); if (!result) { throw new IOException("failed to create " + f); } return new FileOutputStream(f); } }