Java tutorial
//package com.java2s; import java.io.*; public class Main { static String readStringFromFile(File theFile) { String myReturnString; if (theFile == null) { myReturnString = "No File was opened"; } else { try { FileInputStream in = new FileInputStream(theFile); int size = (int) theFile.length(); byte[] data = new byte[size]; /* let's read in the file (which may not all arrive in one chomp...)*/; int bytes_read = 0; while (bytes_read < size) { bytes_read += in.read(data, bytes_read, size - bytes_read); } ; myReturnString = new String(data); // used to be new String( data, 0 ); } catch (Exception exc) { myReturnString = "Error opening file:" + exc; } ; } ; return myReturnString; } }