How to Create Multiple Text Files in Java

Create Multiple Text Files in Java

Hello everyone! In this tutorial, We will show you simple program about, How to create multiple text files in Java. This example program has been tested and shared in the same post.

Example Program

package com.dineshkrish;

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

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class FileUtils {

	public static void createAtoZ(String extension) throws IOException {
		if (extension != null && !extension.isEmpty()) {
			for (int i = 65; i < 91; i++) {

				File file = new File("" + (char) i + "." + extension);

				if (file.createNewFile()) {

					System.out.println(file.getName() + " is created!");
				}
			}
		} else {
			System.out.println("Provide File Extension");
		}
	}

	public static void main(String[] args) {

		try {
			FileUtils.createAtoZ("txt");
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}

}

Output

A.txt is created!
B.txt is created!
C.txt is created!
D.txt is created!
E.txt is created!
F.txt is created!
G.txt is created!
H.txt is created!
I.txt is created!
J.txt is created!
K.txt is created!
L.txt is created!
M.txt is created!
N.txt is created!
O.txt is created!
P.txt is created!
Q.txt is created!
R.txt is created!
S.txt is created!
T.txt is created!
U.txt is created!
V.txt is created!
W.txt is created!
X.txt is created!
Y.txt is created!
Z.txt is created!

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.