当前位置: 代码迷 >> J2SE >> 写入文件有关问题.
  详细解决方案

写入文件有关问题.

热度:21   发布时间:2016-04-24 14:55:04.0
写入文件问题...!在线等
为什么我输入字符串后,不能写入文本,请高手帮我看看是什么原因啊,!


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));
  相关解决方案