{
public static void main(String args[]) throws Exception
{

        System.out.println("dd");
char c;
StringBuffer buf = new StringBuffer();
while((c=(char)System.in.read())!='\n')
buf.append(c);
         buf.append('/n');
byte b[]=buf.toString().trim().getBytes();
RandomAccessFile f1 = new RandomAccessFile("zz.txt","rw"); 
f1.seek(f1.length());
f1.write(b);
f1.close();
}
}

解决方案 »

  1.   

    buf.append('\n');
    sorry 好像反了。
      

  2.   

    你可以试试PrintWriter类,他的Println()方法是每次输出一行。PrintWriter out = new PrintWriter(new FileOutputStream("zz.txt","rw");while((c=(char)System.in.read())!='\n')
    buf.append(c);
             out.println(buf.toString());
    可以试试看。
      

  3.   

    文本文件啊,如果你不想先读到数组里进行排序的话
    就读到excel里,调用它的函数排序再写回去喽
    用jxl包可以做到
      

  4.   

    用 liuchuan(不得安息) 的方法
      

  5.   

    import java.io.*;
    public class zcy
    {
    public static void main(String args[]) throws Exception
    {        System.out.println("dd");
    char c;
    StringBuffer buf = new StringBuffer();
    while((c=(char)System.in.read())!='\n')
    buf.append(c);
    byte b[]=buf.toString().trim().getBytes();
    RandomAccessFile f1 = new RandomAccessFile("zz.txt","rw");
    f1.seek(f1.length());
    f1.write(b);
        f1.writeBytes( System.getProperty( "line.separator" ) );
    f1.close();
    }
    }