还有学生类的代码如下import java.io.*;
public class Student implements Serializable{
private int intId;
private String strName;
private float fChinese;
private float fEnglish;
private float fMath;
public float averageOne()
{
return (fChinese+fEnglish+fMath)/3;
}
public void setId(int intId)
{
this.intId = intId;
}
public void setName(String strName)
{
this.strName = strName;
}
public void setChinese(float fChinese)
{
this.fChinese = fChinese;
}
public void setEnglish(float fEnglish)
{
this.fEnglish = fEnglish;
}
public void setMath(float fMath)
{
this.fMath = fMath;
}
public int getId()
{
return intId;
}
public String getName()
{
return strName;
}
public float getChinese()
{
return fChinese;
}
public float getEnglish()
{
return fEnglish;
}
public float getMath()
{
return fMath;
} }
public class Student implements Serializable{
private int intId;
private String strName;
private float fChinese;
private float fEnglish;
private float fMath;
public float averageOne()
{
return (fChinese+fEnglish+fMath)/3;
}
public void setId(int intId)
{
this.intId = intId;
}
public void setName(String strName)
{
this.strName = strName;
}
public void setChinese(float fChinese)
{
this.fChinese = fChinese;
}
public void setEnglish(float fEnglish)
{
this.fEnglish = fEnglish;
}
public void setMath(float fMath)
{
this.fMath = fMath;
}
public int getId()
{
return intId;
}
public String getName()
{
return strName;
}
public float getChinese()
{
return fChinese;
}
public float getEnglish()
{
return fEnglish;
}
public float getMath()
{
return fMath;
} }
public FileOutputStream(String name,
boolean append)
throws FileNotFoundException创建一个向具有指定 name 的文件中写入数据的输出文件流。如果第二个参数为 true,则将字节写入文件末尾处,而不是写入文件开始处。创建一个新 FileDescriptor 对象来表示此文件连接。
首先,如果有安全管理器,则用 name 作为参数调用 checkWrite 方法。 如果该文件存在,但它是一个目录,而不是一个常规文件;或者该文件不存在,但无法创建它;抑或因为其他某些原因而无法打开它,则抛出 FileNotFoundException。
参数:
name - 与系统有关的文件名
append - 如果为 true,则将字节写入文件末尾处,而不是写入文件开始处
抛出:
FileNotFoundException - 如果该文件存在,但它是一个目录,而不是一个常规文件;或者该文件不存在,但无法创建它;抑或因为其他某些原因而无法打开它。
SecurityException - 如果存在安全管理器,且其 checkWrite 方法拒绝对文件进行写入访问。
从以下版本开始:
JDK1.1
另请参见:
SecurityManager.checkWrite(java.lang.String)
import java.io.*;
import java.util.*;public class test{
public static void main(String[] args){
test t = new test();
for(int i = 0;i<10;i++){
t.write(i);
}
}
void write(int i){
try {
FileOutputStream fos = new FileOutputStream("text.txt",true);
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes(i+"nihao ");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}大哥你看看上面这个代码怎么运行。。
无论运行多少遍,都会在尾部添加