Java File Read via ByteBuffer readTxtFromFile(File file)

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

Description

read Txt From File

License

Open Source License

Declaration

public static String readTxtFromFile(File file) throws Exception 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;

import java.nio.ByteBuffer;

public class Main {
    public static String readTxtFromFile(File file) throws Exception {
        ByteBuffer buffer = ByteBuffer.allocate((int) file.length());
        FileInputStream in = new FileInputStream(file);
        in.getChannel().read(buffer);/*  w w  w  .ja v  a 2s . co  m*/
        in.close();
        return new String(buffer.array());
    }
}

Related

  1. readStringFromSocketChannel(SocketChannel sc)
  2. readStringInUTF8(DataInput in)
  3. readToBuffer(final String filename)
  4. readToByteArray(String fname)
  5. readTwoByteInt(byte[] array, int start)
  6. readUint32(final DataInput di)
  7. readUint32AsInt(DataInput di)
  8. readUintLE(byte[] bytes, int pointer, int size)
  9. readUnsignedInt(InputStream is)