Here you can find the source of readLine(RandomAccessFile file, long position, int trim)
public static String readLine(RandomAccessFile file, long position, int trim) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.RandomAccessFile; public class Main { /**/*www . ja v a 2s. c o m*/ * Reads a line truncating it as needed. * Assumes that hasPrevious was previously called. */ public static String readLine(RandomAccessFile file, long position, int trim) throws IOException { StringBuilder input = new StringBuilder(); int c = -1; boolean eol = false; int count = 0; file.seek(position); while (!eol) { switch (c = file.read()) { case -1: case '\n': eol = true; break; case '\r': eol = true; long cur = file.getFilePointer(); if ((file.read()) != '\n') { file.seek(cur); } break; default: if (-1 != trim && count >= trim) { eol = true; break; } input.append((char) c); count++; break; } } if ((c == -1) && (input.length() == 0)) { return null; } return input.toString(); } }