java file creation

When creating a file with java, use the createNewFile method of the File class. File newfile = new File ("/ Users / Shared / java / filename"); If a file with the same name already exists, it will fail to be created and will return false.

Sample code

public class fileClass{
	public fileClass() throws IOException{
		
		File file = new File("/Users/Shared/java/java.txt");
		
		//Create a file using the createNewFile method
		if (file.createNewFile()){
			System.out.println("File creation successful");
		}else{
			System.out.println("File creation failure");
		}
	}
}

Note that if the specified destination directory cannot be found, an "IOException" exception will occur.

Recommended Posts

java file creation
java directory creation
Eclipse ~ Java project creation ~
Read Java Property file
java (split source file)
java core: chopped core file
Java Discord Bot creation
[Java] Calculator program creation 1
Java multi-project creation with Gradle
[Java] Creation of original annotation
[Java] Create a temporary file
Java
[Java] [Android] Read ini file
Java
Read Java properties file in C #
Upload a file using Java HttpURLConnection
[Splunk] Build Splunk Enterprise (docker file creation)
Run a batch file from Java
Unzip the zip file in Java
Log output to file in Java
Arbitrary string creation code by Java
EXCEL file update sample with JAVA
About file copy processing in Java
Java learning (0)
Studying Java ―― 3
[Java] array
[Java] Annotation
[Java] Module
Java array
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
[Java] How to use the File class
java (override)
java (method)
Java Day 2018
java (array)
Java static
Java serialization
JAVA paid
Java (set)
java shellsort
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
Java features
[Rails] views file creation # text is displayed
Java features
java beginner 3
Java memo