1

I have a for loop that in each iteration a text file should be generated. The problem is naming text file. Because of lack of my knowledge in java, I don't know how I should name output files dynamically. The names should be dependent to the index of for loop. Thanks in advance. I am using printstream.

MTT
  • 5,113
  • 7
  • 35
  • 61

1 Answers1

5

Just build a File Name from your index variable.

for(int x = 0; x < 10; x++){
    String fileName = "file_" + x + ".txt";
    File file = new File(fileName);
}
Matt Clark
  • 27,671
  • 19
  • 68
  • 123