读书人

大家伙儿帮个忙有关JAVA输出

发布时间: 2013-06-25 23:45:42 作者: rapoo

大家帮个忙,有关JAVA输出。
我要输出之多个文件,代码如下,但是为什么文件生成了,但是里面却没有内容?谢谢!

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();

读书人网 >J2SE开发

热点推荐