Android UTF8 File Read loadUTF8(File file)

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

Description

load UTF

Declaration

public static String loadUTF8(File file) throws IOException 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    public static String loadUTF8(File file) throws IOException {
        FileInputStream is = new FileInputStream(file);
        try {/*from w w w. j  a  va 2  s . c  o  m*/
            byte[] buf = new byte[1024];
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            while (true) {
                int read = is.read(buf);
                if (read == -1)
                    break;
                bos.write(buf, 0, read);
            }
            return new String(bos.toByteArray(), "UTF-8");
        } finally {
            is.close();
        }
    }
}

Related

  1. loadUTF8LinesFromFile(File file)
  2. readFile(String fileName, String encoding)
  3. readFromFile(String fileName)