How to create a file in Java,while working with different files in Java it is very important to creating new files whether it could be any format to store the data.In this post you will learn how to create a files in java grammatically,please observe below simple example to create a file in Java.
Also Read - Extract Number from a String
How to create a file in Java
For creating files in java you can use File.createNewFile() method is used to create a new file in Java language and which will return Boolean value means whether it is a true or false after creating the file in java.
Example:
package com.java.filescreateread;
import java.io.File;
import java.io.IOException;
public class CreateFiles {
public static void main(String[] args) throws IOException {
File file = new File("E:\\java\\Files\\Simplefiless.csv");
file.createNewFile();
if(file.isFile()){
System.out.println("New CSV file is created");
}else{
System.out.println("New CSV file is not created and already exists.");
}
}
}
Here in above code new file is created and as well as it will verify whether file is exists in created path or not.Please provide your comments on this post.
0 Komentar
Penulisan markup di komentar