用java.io.FileReader和java.io.FileWriter

解决方案 »

  1.   

    使用BufferedReader 中的public String readLine()方法,然后将string 打印到屏幕即可
      

  2.   

    java.io.RandomAccessFile类readLine方法可以这么做:
    RandomAccessFile file=new RandomAccessFile("file.txt","rw");
    String line=new String();
    while ((line=file.readLine()!=null)
    {
        System.out.print(line);
    }
    以下是jdk的api文档的解释readLine
    public final String readLine()
                          throws IOException
    Reads the next line of text from this file. This method successively reads bytes from the file, starting at the current file pointer, until it reaches a line terminator or the end of the file. Each byte is converted into a character by taking the byte's value for the lower eight bits of the character and setting the high eight bits of the character to zero. This method does not, therefore, support the full Unicode character set. 
    A line of text is terminated by a carriage-return character ('\r'), a newline character ('\n'), a carriage-return character immediately followed by a newline character, or the end of the file. Line-terminating characters are discarded and are not included as part of the string returned. This method blocks until a newline character is read, a carriage return and the byte following it are read (to see if it is a newline), the end of the file is reached, or an exception is thrown.Specified by: 
    readLine in interface DataInput
    Returns:
    the next line of text from this file, or null if end of file is encountered before even one byte is read.
    Throws:
    IOException - if an I/O error occurs.