Creating a File - Java File Path IO

Java examples for File Path IO:File Operation

Description

Creating a File

Demo Code

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

public class Main {
  public void m() {
    try {/*from ww  w . j  a va  2 s  .c  om*/
      File file = new File("filename");

      // Create file if it does not exist
      boolean success = file.createNewFile();
      if (success) {
        // File did not exist and was created
      } else {
        // File already exists
      }
    } catch (IOException e) {
    }
  }
}

Related Tutorials