Here you can find the source of readFile(String path)
public static String readFile(String path)
//package com.java2s; /*//w w w .ja v a2 s . c o m * Copyright (c) 2015, Varav Inc. All rights reserved. * License terms are included in LICESNSE.txt file. */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import javax.swing.JOptionPane; import javax.swing.UIManager; public class Main { public static String readFile(String path) { StringBuilder result = new StringBuilder(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(path)); String buffer; while ((buffer = reader.readLine()) != null) { result.append(buffer + '\n'); } reader.close(); } catch (IOException e) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); JOptionPane.showMessageDialog(null, "<html><br>Could not read from file: " + path + "<br>" + "Error: " + e.toString() + "</html>", "Error!", JOptionPane.ERROR_MESSAGE); } catch (Exception ee) { } e.printStackTrace(); } return result.toString(); } public static String[] readFile(String path1, String path2) { return new String[] { readFile(path1), readFile(path2) }; } }