Java UTF8 File Read loadUTF8(File file)

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

Description

load UTF

License

Open Source License

Declaration

public static String loadUTF8(File file) throws IOException 

Method Source Code


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

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class Main {
    public static String loadUTF8(File file) throws IOException {
        FileInputStream is = new FileInputStream(file);
        try {/*from w  w w. j  av  a2  s . co  m*/
            return loadUTF8(is);
        } finally {
            is.close();
        }
    }

    public static String loadUTF8(InputStream is) throws IOException, UnsupportedEncodingException {
        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");
    }
}

Related

  1. getBufferedUTF8Reader(InputStream inputStream)
  2. getUtf8BytesFromFile(String fileName)
  3. getUtf8FileWriter(String file, boolean append)
  4. getUTF8InputStreamReader(InputStream stream)
  5. getUTF8Reader(File f)
  6. makeUTF8Reader(InputStream inputStream)
  7. newUtf8Reader(final InputStream in)
  8. openFileReaderUTF8(File file)
  9. readAllLines(File inputFile)