我要输出之多个文件,代码如下,但是为什么文件生成了,但是里面却没有内容?谢谢!
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class test {
public static void main(String args[])throws Exception{
String[] filename = new String[101];
for (int n = 0;n<101;n++)
{
filename[n]="src/Testvec" + n + ".txt";
java.io.File testvec = new File(filename[n]);
java.io.PrintWriter testout = new PrintWriter(testvec);
testout.print("The weather is good!");
}
}
}
Java
------解决方案--------------------
import java.io.File;
import java.io.PrintWriter;
public class testMe {
public static void main(String args[])throws Exception{
String[] filename = new String[101];
for (int n = 0;n<11;n++)
{
filename[n]="a" + n + ".txt";
java.io.File testvec = new File(filename[n]);
java.io.PrintWriter testout = new PrintWriter(testvec);
testout.print("The weather is good!");
testout.flush();
testout.close();
}
}
}
------解决方案--------------------
testout.flush();
------解决方案--------------------
FileOutputStream fo = new FileOutputStream("1.txt");
PrintWriter ps = new PrintWriter(fo);
ps.println("经过阿拉穆·哈尔发一战,轴心国军队损失惨重。德军与意军的士兵都变得很疲惫,并且他们只能靠缴获的盟军给养来维持生活。");
ps.close();
fo.close();