Java BufferedReader Read Line readLine(RandomAccessFile wiki)

Here you can find the source of readLine(RandomAccessFile wiki)

Description

read Line

License

Apache License

Declaration

public static String readLine(RandomAccessFile wiki) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    private static final String NEWLINE = System.lineSeparator();

    public static String readLine(RandomAccessFile wiki) throws IOException {
        long start = wiki.getFilePointer();
        wiki.readLine();//  w w  w . j a  va2 s.  c o m
        long end = wiki.getFilePointer();
        wiki.seek(start);
        byte[] b = new byte[(int) (end - start)];
        wiki.read(b);
        return new String(b).replace(System.lineSeparator(), "");
    }

    public static String read(String file) throws FileNotFoundException, IOException {
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            return read(br);
        }
    }

    public static String read(BufferedReader br) throws IOException {
        StringBuffer sbuff = new StringBuffer();
        String ln;
        while ((ln = br.readLine()) != null)
            sbuff.append(ln).append(NEWLINE);
        return sbuff.toString();
    }
}

Related

  1. readLine(File file, int lineNumber)
  2. readLine(InputStream in)
  3. readLine(InputStream in)
  4. readLine(InputStream input)
  5. readLine(InputStream input)
  6. readLine(Reader rd)
  7. readLine(String fileName)
  8. readLine(String fileName)
  9. readLine(String filename, String encoding)