Here you can find the source of readFromFile(final String path)
Parameter | Description |
---|---|
path | the path of the file |
Parameter | Description |
---|---|
IOException | if a problem occurs while reading the |
public static String readFromFile(final String path) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.RandomAccessFile; public class Main { /**//from w w w . j a v a 2s.c om * Reads a file into a string. * * @param path the path of the file * @return the text read from the file * @throws IOException if a problem occurs while reading the */ public static String readFromFile(final String path) throws IOException { final RandomAccessFile access = new RandomAccessFile(path, "r"); final StringBuffer result = new StringBuffer(); try { while (access.getFilePointer() < access.length()) { result.append(access.readLine() + "\n"); } } finally { access.close(); } return result.toString(); } }