Creating a file and use if statement to check if the creation is successful - Java File Path IO

Java examples for File Path IO:File Operation

Description

Creating a file and use if statement to check if the creation is successful

Demo Code

import java.io.File;
import java.io.IOException;

public class Main {
  public static void main(String[] arg) throws IOException {
    File f = new File("c:/myfile.txt");

    if (f.createNewFile())
      System.out.println("File created.");
    else/*from   ww w . java 2  s  . com*/
      System.out.println("File could not be created.");

  }
}

Related Tutorials