import java.io.*;public class TestBuffer{
public static void main(String args[]){
FileReader fi = null;
BufferedReader  bs = null;

try{
fi = new FileReader("E:\\corejava\\411\\青花瓷.txt");
bs = new BufferedReader(fi);
String ch = null;

while((ch=bs.readLine())!="\r" ){

System.out.print(ch);
if(ch == null) 

break;  
}  }


}catch(Exception e){
System.out.println("文件复制失败");
}

System.out.println(txt);
}
}

解决方案 »

  1.   

    我只能全部读出来 我想回车一下读一行 如何修改[ar:周杰伦]
    [al:我很忙]
    [by:style海峰]
    [00:00.40]周杰伦 - 青花瓷 
    [00:03.24]作词:方文山 作曲:周杰伦
    [00:06.29]编曲:钟兴民
    [00:09.79]LRC制作:369歌词组●style海峰
      

  2.   

    干嘛要 == '\r' 啊?br.readLine() 本身就是一行一行读的。for(String str = null; (str = br.readLine()) != null; ) {
        System.out.println(str);
    }
      

  3.   

    我开始读个 [ar:周杰伦]
    在CMD显示出来
    然后回车 又显示
    [al:我很忙]
      

  4.   

    package org.csdn;import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;public class Read
    { /**
     * @param args
     */
    public static void main(String[] args)
    { FileReader fi = null;
    BufferedReader bs = null;
    List<String> line = new ArrayList<String>();
    try
    {
    fi = new FileReader("E:\\青花瓷.txt");
    bs = new BufferedReader(fi);
    String ch = null; while ((ch = bs.readLine()) != null)
    {
    System.out.println(ch);
    line.add(ch);
    }
    }
    catch (Exception e)
    {
    System.out.println("文件复制失败");
    } Scanner sc = new Scanner(System.in);
    // 从键盘接收数据
    System.out.println("请输入数据:");
    int i = 0;
    while (true)
    {
    if (sc.hasNextLine())
    {
    if (i < line.size())
    {
    System.out.println(line.get(i));
    i++;
    sc.next();
    }
    else
    {
    break;
    }
    }
    }
    }
    }
      

  5.   

    多谢 ,JAVA写这个还是有点麻烦啊
      

  6.   

    10#的是把txt先复制到 ArrayList中,然后再根据条件循环处理。我认为问题出在if (i < line.size())
    中,这样的话当然一按回车,所有的就输出来了,if(i<line.size()&&(line.get(i)!=\n)),我的意思是把每一行录入到ArrayList中的时候,每一行的结束应该有一个换行符,看能 不能在这上面做点文章,小弟初学,还望各位大侠鉴定。
      

  7.   

    import java.io.*;
    public class test {
    public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new FileReader("d:\\a.txt"));
    String s = reader.readLine();
    while (s != null)
    {
    System.out.println(s);
    System.in.read();
    System.in.skip(2);
    s = reader.readLine();
    }
    reader.close();
    }
      

  8.   


    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;
    import java.nio.MappedByteBuffer;
    import java.nio.channels.FileChannel;public class Test {        //NIO的实现方法
    private void nioReadFile(String filePath) {
    if(filePath==null)
    throw new NullPointerException();

    FileInputStream in = null;
    BufferedReader inputStream = null;
    try {
    in = new FileInputStream(new File(filePath));
    FileChannel fileChannel = in.getChannel();
    MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
    byte[] upArray = new byte[(int) fileChannel.size()];
    mappedByteBuffer.get(upArray);
    String str = new String(upArray);
    String[] strArray = str.split("\r\n"); inputStream = new BufferedReader(new InputStreamReader(System.in));
    int i = 0; while (!inputStream.readLine().equals("exit") && i != strArray.length) {
    System.out.print(strArray[i]);
    i++;
    } } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    if (in != null)
    in.close();
    if (inputStream != null)
    inputStream.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
            //IO的实现方法
    private void ioReadFile(String filePath) {
    if(filePath==null)
    throw new NullPointerException();

    LineNumberReader in = null;
    BufferedReader inputStream = null;

    try {
    in = new LineNumberReader(new FileReader(new File(filePath)));
    inputStream = new BufferedReader(new InputStreamReader(System.in));

    String str=null; while (!inputStream.readLine().equals("exit") && (str=in.readLine()) != null) {
    System.out.print(str);
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    if (in != null)
    in.close();
    if (inputStream != null)
    inputStream.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    } public static void main(String[] args) throws Exception {
    //如果要测试nio就注释掉下面这行把nio这行的注释去掉
    new Test().ioReadFile("E:\\青花瓷.txt");
    //new Test().nioReadFile("E:\\青花瓷.txt");
    }}