Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 for 循环,在每次迭代中都应该生成一个文本文件。问题是命名文本文件。由于缺乏Java知识,我不知道如何动态命名输出文件。名称应取决于 for 循环的索引。提前致谢。我正在使用打印流。
只需从您的索引变量构建一个文件名。
for(int x = 0; x < 10; x++){ String fileName = "file_" + x + ".txt"; File file = new File(fileName); }