A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[Java]Simple Text File Creator

1.3k views · started by ksrocks333 ·
#1
[Java]Simple Text File Creator
It basically makes multiple text files w/ a message. You can just put a space if you want blank text files.
Example input / output:
Number of files to create:
3
Name to give file:
test
Write to file:
hello
Done creating. Check project folder.

Created Files: (in project folder)
test0
test1
test2
(each w/ the word hello in them)


Source

import java.io.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int num;
String message = "";
String name = "";
InputStreamReader strinput = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(strinput);
System.out.println("Number of files to create: ");
num = input.nextInt();
System.out.println("Name to give file: ");
try{name = reader.readLine();}catch(Exception e){}
System.out.println("Write to file: ");
try{message = reader.readLine();}catch(Exception e){}
for(int x = 0; x<num; x++)
{
try
{
FileWriter fstream = new FileWriter(name + x + ".txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(message);
out.close();
}catch (Exception e){System.err.println("Error: " + e.getMessage());}
}
System.out.println("Done creating. Check project folder.");
}
}
#2
Great source code darling :)

Im greatly proud you have moved onto a good language like java :)
#3
Thanks Bman, I appreciate it.