为什么我输入字符串后,不能写入文本,请高手帮我看看是什么原因啊,!
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");
}
}
}

解决方案 »

  1.   

    最后你不想输入的时候, 请按各ctrl + z,通知BufferedReader ,我的输入结束了。
    不然怎么认识啊?
      

  2.   

    但是我按ctrl+z后..
    前面输入的Name,ID,DS,DB就被覆盖咯,还出现null值诶.!
      

  3.   

    --------------------------------------------------------------------
    BufferedWriter fo = new BufferedWriter(new FileWriter("c:\\student.txt"));
    --------------------------------------------------------------------
    改為:
    BufferedWriter fo = new BufferedWriter(new FileWriter("c:\\student.txt",true));
      

  4.   

    不会吧..
    我运行输入值后
    就显示一些莫名奇妙的东西,
    不知道是什么原因,怪事啊.!for (int i = 0; i < info.length; i++)
    {
        info[i] = reader.readLine();
        record += info[i];  //就是这里导致出现NULL值.
    }还有Name,ID,DS,DB字符串被覆盖..
    我想要的输出结果是这样的,Name,ID,DS,DB
    dd 001 99 98
    aa 002 99 90
      

  5.   

    只要我输入一组记录比如dd 001 99 98,就肯定出现NULL
    如果输入两组的话,就后面一组是NULL值,前面一组正常显示,但是不能换行,!
    我定义了String record = "\n";