java - 输出只给我一行

标签 java

任何人都可以在这里为我指出正确的方向吗?我有一个方法应该读取文件并显示该文件中的数据。我只能让它显示一行。我知道这很简单,我忽略了,但我的大脑很糊涂,我只是不断地挖一个更大的洞。

public static String readFile(String file) {
    String data = "";
    if (!new java.io.File(file).exists()) {
        return data;
    }
    File f = new File(file);
    FileInputStream fStream = null;
    BufferedInputStream bStream = null;
    BufferedReader bReader = null;
    StringBuffer buff = new StringBuffer();

    try {
        fStream = new FileInputStream(f);
        bStream = new BufferedInputStream(fStream);
        bReader = new BufferedReader(new InputStreamReader(bStream));
        String line = "";

        while (bStream.available() != 0) {
            line = bReader.readLine();

            if (line.length() > 0) {
                if (line.contains("<br/>")) {
                    line = line.replaceAll("<br/>", " ");
                    String tempLine = "";
                    while ((tempLine.trim().length() < 1)
                            && bStream.available() != 0) {
                        tempLine = bReader.readLine();
                    }
                    line = line + tempLine;
                }
                buff.append(line + "\n");

            }
        }

        fStream.close();
        bStream.close();
        bReader.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return buff.toString();

}

最佳答案

String line = null;
while ((line = bReader.readLine())!=null)

关于java - 输出只给我一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393474/

相关文章:

java - 将参数数组传递给 Quartz Scheduler

java.lang.ClassCastException :xx cannot be cast to org. apache.avro.generic.IndexedRecord

java - java 中的 mouseclicked 事件无法填充文本字段

java - 使用 JSch 将一个文件从远程计算机复制到另一台远程计算机

java - 我可以在 EJB 3.2 中获得类似实体 bean 的东西吗?

java - 如何将当前数据库更改为另一个?

java - 是否可以在 spring 中映射来自同一个 requestBody 的两个对象?

java - 从命令行获取 pom.xml 属性

java - Neo4j 节点之间的方向

java - TransactionRequiredException 执行更新/删除查询