import java.io.*;
public class ReadWrite {    public static void main(String[] args) throws Exception {
        String inFileName = "";    // XXX
        String outFileName = "";   // XXX
        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFileName)));
        PrintStream   out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outFileName)));        String s = null;
        while ((s=in.readLine()) != null) out.println(s);
        out.close();
        in.close();
    }}

解决方案 »

  1.   

    你用pringln()啊,我就可以多行读出/写入啊
      

  2.   

    FileOutputStream
    public FileOutputStream(String name,
                            boolean append)
                     throws FileNotFoundException
    Creates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection. 
    First, if there is a security manager, its checkWrite method is called with name as its argument. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown. 
    Parameters:
    name - the system-dependent file name
    append - if true, then bytes will be written to the end of the file rather than the beginning 
    Throws: 
    FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason. 
    SecurityException - if a security manager exists and its checkWrite method denies write access to the file.
    Since:
    JDK1.1 
    See Also:
    SecurityManager.checkWrite(java.lang.String)看看上面的你就知道了,只要你构造文件输出流FileOutputStream(String name,
                            boolean append)
    设置好第2个参数就可以了,当append为true时,就是向文件中追加内容,也就是你要实现的功能。
      

  3.   

    读内容就是用如下:
     
    BufferedReader in = new BufferedReader(new FileReader(configpath));
                  in.readLine();
    其中configpath就是你的文件的路径。
    你应该明白了,这样你的问题,读一行,和追加不都实现了
      

  4.   

    例如从键盘读入文本行,并写入"test.txt"文件,直到键入“stop”为止:
    FileWriter fw;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    fw = new FileWriter("test.txt");
    String str;
    System.out.println("Enter Text ('stop' to quit).");
    do{
      str = br.readLine();
      if(str.compareTo("stop") == 0) break;
      str = str + "\r\n";
      fw.write(str);
    } while(str.compareTo("stop" != 0);
    fw.close();读出时只要用readLine()方法就可以了。