为什么我输入字符串后,不能写入文本,请高手帮我看看是什么原因啊,!
import java.io.*;
public class temp
{
public static void main(String [] args)
{
try
{
String head = "Name,ID,DS,DB ";
byte[] c = new byte[40];
c = head.getBytes();
System.out.println(new String(c));
String record = " ";
BufferedWriter fo = new BufferedWriter(new FileWriter( "c:\\student.txt "));
String[] info = new String[4];
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < info.length; i++)
{
info[i] = reader.readLine();
record += info[i];
}
/*String record = " ";
for(String s in info)
{
record += s;
}*/
fo.write(record);
fo.close();
}
catch (FileNotFoundException fe)
{
System.out.println( "File Not Found ");
}
catch (IOException ie)
{
System.out.println( "IO Exception ");
}
}
}
------解决方案--------------------
--------------------------------
BufferedWriter fo = new BufferedWriter(new FileWriter( "c:\\student.txt "));
--------------------------------
改為:
BufferedWriter fo = new BufferedWriter(new FileWriter( "c:\\student.txt ",true));