Android Text File Read getContent(String file, String encodType)

Here you can find the source of getContent(String file, String encodType)

Description

get Content

Declaration

public static String getContent(String file, String encodType)
            throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.DataInputStream;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    public static String getContent(String file, String encodType)
            throws IOException {
        // "xx\r\n" read -> "xx"
        StringBuffer content = new StringBuffer();
        FileInputStream fis = new FileInputStream(file);
        DataInputStream dis = new DataInputStream(fis);
        BufferedReader br = new BufferedReader(new InputStreamReader(dis,
                encodType));/*from w w  w  .  j a  v a 2 s  .  c  o m*/
        String line = null;
        if ((line = br.readLine()) != null) {
            content.append(line);
        }
        while ((line = br.readLine()) != null) {
            content.append("\r\n" + line);
        }
        br.close();
        dis.close();
        fis.close();
        return content.toString();
    }
}

Related

  1. readStringFromFile(String fileName)
  2. readText(String path)
  3. readTextFile(String filePath)
  4. readTextFile(String path)
  5. setFileResourceText(String path, String content)
  6. getString(File file)
  7. readFileSdcard(File file)
  8. readFromFile(Context context, String fileName)
  9. loadTextFile(Context context, String textFile)