徵求高手幫忙,JAVA初學者的問題
按照課本裡面的習題,我先寫出了以下的程式。
import java.io.*;
class Data
{
private String name;
private int english;
private int math;
public Data(String str, int e, int m)
{
name = str;
english = e;
math = m;
}
public void writeData() throws IOException
{
FileWriter fw = new FileWriter("D:\\student.txt");
BufferedWriter bfw = new BufferedWriter(fw);
bfw.write(name);
bfw.write(english);
bfw.write(math);
fw.close();
}
}
public class my_test
{
public static void main(String args[]) throws IOException
{
Data stu1 = new Data("Ariel", 92, 85);
Data stu2 = new Data("Fiona", 67, 89);
stu1.writeData();
stu2.writeData();
}
}
但是輸出到「D:\student.txt」後,資料夾打開裡面只剩下Fiona而已,想請問兩個問題:
1.要如何讓原本寫在資料夾內的資料不被覆蓋過去呢?
2.把buffer的資料寫入後,english和math是想要出現成績,但是卻出現了「YC」,想請問要如何處理?
想要輸出為
Ariel 92 85
Fiona 67 89