Skip to content

Instantly share code, notes, and snippets.

@SmashedFrenzy16
Created March 28, 2022 15:26
Show Gist options
  • Save SmashedFrenzy16/fc0a7ba94886ea42fe05e651d00124f1 to your computer and use it in GitHub Desktop.
Save SmashedFrenzy16/fc0a7ba94886ea42fe05e651d00124f1 to your computer and use it in GitHub Desktop.
A Java File Creator.
import java.io.File;
import java.io.IOException;
public class fileCreator {
public static void main(String[] args) {
try {
File myObj = new File("textdoc1.txt");
if (myObj.createNewFile()) {
System.out.println("The following file was created: " + myObj.getName());
} else {
System.out.println("This file already exists on this device.");
}
} catch (IOException e) {
System.out.println("An error occured.");
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment