Here you can find the source of readFile(File input)
Parameter | Description |
---|---|
input | text file |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
public static String readFile(File input) throws FileNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { /**//from www.ja va 2 s. c o m * Reads a file and outputs it as String * @param input text file * @return String document * @throws FileNotFoundException */ public static String readFile(File input) throws FileNotFoundException { StringBuilder fileBuffer = new StringBuilder((int) input.length()); Scanner scanner = new Scanner(input); try { while (scanner.hasNextLine()) { fileBuffer.append(scanner.nextLine()).append('\n'); } } finally { scanner.close(); } return fileBuffer.toString(); } }