import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Test2 {
public static void main(String[] args) throws IOException {
File file = null;
FileWriter fw = null;
for(int i=1;i<511;i++){
file = new File("D:/test/repository"+i+".txt");
try {
if (!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(file);
//向文件中写内容
fw.write(" function initTable() public {\n" +
"\n" +
" info[0]=\"repository1\";\n" +
" info[1]=\"tablename\";\n");
for(int j=2;j<i+2;j++){
fw.write(" info["+j+"]=\"data"+(j-1)+"\";\n");
}
fw.write(" }\n" +
"\n" +
"}");
fw.flush();
System.out.println("写数据成功!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(fw != null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
fw.close();
}
}
Java实现批量生成txt文件,并在文件中插入内容
最新推荐文章于 2024-05-17 13:22:08 发布