Q:

Java program to create a new file

0

Java program to create a new file

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Create New File using Java Program

// Java program to create new file

import java.io.File;

public class CreateFile {
  public static void main(String args[]) {
    final String fileName = "file1.txt";

    try {
      File objFile = new File(fileName);
      if (objFile.createNewFile()) {
        System.out.println("File created successfully.");
      } else {
        System.out.println("File creation failed!!!");
      }
    } catch (Exception Ex) {
      System.out.println("Exception : " + Ex.toString());
    }
  }
}

Output:

    
File created successfully.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now