Android File Read readFile(File file)

Here you can find the source of readFile(File file)

Description

read File

Declaration

public static String readFile(File file) throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String readFile(File file) throws IOException {
        StringBuffer fileData = new StringBuffer(1000);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);//from  w w w .  j  a va  2  s.c o  m
            buf = new char[1024];
        }
        reader.close();
        return fileData.toString();
    }
}

Related

  1. read(File path, int i)
  2. readFile(String filepath)
  3. readFileAsString(String filePath)
  4. readFileToByte(File file)
  5. readFileToString(String fileName)