首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

写入文件有关问题.

2012-01-11 
写入文件问题...!在线等为什么我输入字符串后,不能写入文本,请高手帮我看看是什么原因啊,!importjava.io.*

写入文件问题...!在线等
为什么我输入字符串后,不能写入文本,请高手帮我看看是什么原因啊,!


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

热点排行