getting multiple notepad out put files

hello

i'm trying to make a java program that writes out multiple files to a folder in my documents. However, i'm confused on how to make a for statement that would output a lot of files, while making them still write and not have to replace the previous one.......

this is my program

import java.io.*;

public class notePad{

public static void main(String args[]){

try{

File infile = new File("C:/Documents and Settings/c1s5/My Documents/Allah/sample.txt");

FileOutputStream fos = new FileOutputStream(infile);

PrintWriter out = new PrintWriter(fos);

out.println("This is the sample text in the notepad");

out.flush();

out.close();

}catch(Exception e){}

}

}

and i want to be able to manipulate the sample so that it goes sample 1...sample 2..for every time it runs though the for statement....also, i want to make it output more than one file....anyone have an idea how i can do this...its my fourth month in java...so i'm a noob

hwrd

[1047 byte] By [hwrdrpknsa] at [2007-11-26 17:08:28]
# 1
Adding a loop? http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
zadoka at 2007-7-8 23:36:19 > top of Java-index,Java Essentials,Java Programming...
# 2

import java.io.*;

public class notePad{

public static void main(String args[]){

try{

for(int i=0; i<how many file; i++)

{

File infile = new File("C:/Documents and

Settings/c1s5/My Documents/Allah/sample.txt" + i);

FileOutputStream fos = new FileOutputStream(infile);

PrintWriter out = new PrintWriter(fos);

out.println("This is the sample text in the

notepad");

out.flush();

out.close();

}

}catch(Exception e){}

}

}

Change the file name for each one. as long as you use the same hard coded file name it will overwrite the previous one. The example is hideous and very rought but should give you the idea.

Hope this helps,

PS.>

puckstopper31a at 2007-7-8 23:36:19 > top of Java-index,Java Essentials,Java Programming...
# 3
thanks this was exactly what i was trying to do........
hwrdrpknsa at 2007-7-8 23:36:19 > top of Java-index,Java Essentials,Java Programming...