日期:2014-05-20 浏览次数:20856 次
public class HomeWork6 {
Random random;
FileOutputStream fos;
DataOutputStream dos;
public HomeWork6() {
try {
random = new Random();
fos = new FileOutputStream("E:\\Think in java\\a.txt");
dos = new DataOutputStream(fos);
for(int i=0;i<10;i++) {
int a=random.nextInt(9999);
System.out.println(a);
dos.writeInt(a);
}
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
new HomeWork6();
}
}
public TestInput() {
try {
random = new Random();
fos = new FileOutputStream("E:a.txt");
dos = new DataOutputStream(fos);
for(int i=0;i<10;i++) {
int a=random.nextInt(9999);
System.out.println(a);
fos.write(String.valueOf(a).getBytes());
}
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
------解决方案--------------------