System.out.println("结束了");
String path="F:/text.txt";
File file=new File(path);
if(!file.exists())
file.createNewFile();
FileOutputStream out=new FileOutputStream(file,false); //如果追加方式用true
for (int i = 0; i < questionLength; i++) {
// 对问题进行预处理
out.write((questions.get(i) + "\n").getBytes("utf-8"));
out.write((processedQuestions[i] + "\n").getBytes("utf-8"));
out.write((answers.get(i) + "\n").getBytes("utf-8"));
}
out.close();
String path="F:/text.txt";
File file=new File(path);
if(!file.exists())
file.createNewFile();
FileOutputStream out=new FileOutputStream(file,false); //如果追加方式用true
for (int i = 0; i < questionLength; i++) {
// 对问题进行预处理
out.write((questions.get(i) + "\n").getBytes("utf-8"));
out.write((processedQuestions[i] + "\n").getBytes("utf-8"));
out.write((answers.get(i) + "\n").getBytes("utf-8"));
}
out.close();
本文介绍了一个使用Java进行文件写入的简单示例。示例中创建了一个名为text.txt的文件,并通过FileOutputStream将字符串数组写入该文件。每写入一个问题及其答案后都会换行。
1958

被折叠的 条评论
为什么被折叠?



