Here you can find the source of read_file(File input)
Parameter | Description |
---|---|
input | a parameter |
public static String read_file(File input)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; public class Main { /**/*from ww w .j a v a 2 s.c o m*/ * */ public static String log; /** * * @param input * @return */ public static String read_file(File input) { log = ""; String output = ""; FileInputStream stream; try { stream = new FileInputStream(input); try { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); /* Instead of using default, pass in a decoder. */ output = Charset.defaultCharset().decode(bb).toString(); } finally { stream.close(); } } catch (IOException e) { // TODO: handle exception log += e.getMessage(); return ""; } return output; } }