javafilewriter
import java.io.FileWriter;
import java.io.IOException;
public class JavaFileWriter {
public static void main(String[] args) {
String fileName = "output.txt";
int numWords = 1000;
try {
FileWriter writer = new FileWriter(fileName);
for (int i = 0; i < numWords; i++) {
writer.write("Lorem ipsum dolor sit amet
consectetur adipiscing elit. ");
}
writer.close();
System.out.println("File " + fileName + " has been written successfully.");
} catch (IOException e) {
System.out.println("An error occurred while writing to the file.");
e.printStackTrace();
}
}
}
版权声明:本站内容源自互联网,如有内容侵犯了你的权益,请联系删除相关内容。
上一篇:命名空间模块 下一篇:dockersearch