Hi Forum,
I have 100 text files, I need to write data into them. I am reading data from another file.
Please provide me some guideline for doing this...
Thanks in Advance...
Hi Forum,
I have 100 text files, I need to write data into them. I am reading data from another file.
Please provide me some guideline for doing this...
Thanks in Advance...
Anything tried yet? Or nothing attempted? :(nerd):
Goldest
HI
Above Code will create the file from application0.txt to the end of loop.Code:import java.io.*;
import java.io.Writer;
public class CreateFile2{
public static void main(String[] args) throws IOException{
File f;
try{
String strDirectoy ="test";
String strManyDirectories="Application\\Test\\";
// Create directory
boolean success = (new File(strManyDirectories)).mkdirs();
if (success) {
System.out.println("Directories: " + strManyDirectories + " created");
for (int i=0;i<=100 ;i++)
{
f=new File( ""+ strManyDirectories +""+"Application"+i+".txt");
f.createNewFile();
FileWriter fstream = new FileWriter(f,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
out.close();
}
}
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
I need to write data into them
bye selecting files one by one
Sorry for my English...
Don't do your operation on the basis of,
Instead, create the directory and check if it exists. Something like,Code:if (success) {
Currently your code isn't getting passed through the if statement because when the directory exists it doesn't create it second time and returns false.Code:File dir = new File(strManyDirectories);
dir.mkdirs();
if(dir.exists()){ ....//Rest of the code.
Hope that helps,
Goldest