Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
File | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String readFile(File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.util.Scanner; public class Main { /**//w ww . ja v a 2s . co m * Read a file and convert to String * * @param File * @return String of the content of the file * @throws IOException */ public static String readFile(File file) throws IOException { StringBuilder result = new StringBuilder(""); Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); } scanner.close(); return result.toString(); } }