Java Path File Read nio readLineSP(String filePath, int line, int pos)

Here you can find the source of readLineSP(String filePath, int line, int pos)

Description

Read the context after a specified position of a line in a text file.

License

LGPL

Declaration

public static String readLineSP(String filePath, int line, int pos) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

import java.util.List;

public class Main {
    /**/*from  ww w . j a  va2s.c  o  m*/
     * Read the context after a specified position of a line in a text file.
     */
    public static String readLineSP(String filePath, int line, int pos) throws IOException {
        pos -= 1;
        String l = readLineS(filePath, line);
        if (l.length() < pos)
            pos = l.length();
        l = l.substring(pos, l.length());
        return l;
    }

    /**
     * Read the context of a specified line in a text file.
     */
    public static String readLineS(String filePath, int line) throws IOException {
        File f = new File(filePath);
        List<String> lines = Files.readAllLines(f.toPath());
        return lines.get(line - 1);
    }
}

Related

  1. readLines(Path path, boolean ignoreComments)
  2. readLineS(String filePath, int line)
  3. readLinesFromFile(Path path)
  4. readLinesFromFileLazy(String path)
  5. readLinesOfFile(String path)
  6. readLinesToString(Path file)
  7. readManifest(Path path)
  8. readPropertiesFile(Path path)
  9. readSheBang(Path script)