Here you can find the source of createNewFile(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static File createNewFile(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.IOException; public class Main { public static File createNewFile(String filepath) throws IOException { return createNewFile(new File(filepath)); }/*from ww w. j a v a2s. co m*/ /** * create a new blank file * @param file * @return * @throws IOException */ public static File createNewFile(File file) throws IOException { File pareFile = file.getParentFile(); if (pareFile.exists() || pareFile.mkdirs()) { File newFile = file; if (newFile.exists() || newFile.createNewFile()) return newFile; } return null; } }