Java InputStreamReader Read readFile(String filePath, String charsetName, long lineNow, long lineEnd)

Here you can find the source of readFile(String filePath, String charsetName, long lineNow, long lineEnd)

Description

read File

License

Open Source License

Declaration

public static String readFile(String filePath, String charsetName, long lineNow, long lineEnd) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Main {

    public static String readFile(String filePath, String charsetName) {
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;
        try {/*from  w w w  . j  a v a2s  . c o m*/
            br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charsetName));
            String data = null;
            while ((data = br.readLine()) != null) {
                sb.append(data);
                sb.append("<br/>");

            }
        } catch (Exception e) {
        } finally {
            try {
                br.close();
            } catch (Exception e) {
            }

        }
        return sb.toString();
    }

    public static String readFile(String filePath, String charsetName, long lineNow, long lineEnd) {
        StringBuffer sb = new StringBuffer();
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), charsetName));
            String data = null;
            int i = 0;
            while ((data = br.readLine()) != null) {
                if (i <= lineEnd && i >= lineNow) {
                    sb.append(data);
                    sb.append("<br/>");
                }
                i++;
            }
        } catch (Exception e) {
        } finally {
            try {
                br.close();
            } catch (Exception e) {
            }
        }
        return sb.toString();
    }
}

Related

  1. readFile(String filePath)
  2. readFile(String filePath)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String filePath)
  6. readFile(String input)
  7. readFile(String location)
  8. readFile(String name)
  9. readFile(String nomeFile)