Here you can find the source of readFile(String path)
Parameter | Description |
---|---|
path | the path |
public static String readFile(String path)
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; public class Main { /**/*from w ww .jav a 2 s .c o m*/ * Read file. * * @param path the path * @return the string */ public static String readFile(String path) { try { FileInputStream stream = null; try { stream = new FileInputStream(new File(path)); FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); /* Instead of using default, pass in a decoder. */ return Charset.defaultCharset().decode(bb).toString(); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { stream.close(); } } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return ""; } }