/************************************************************************************************** * Program Name: File Reader * Author: Terry Weiss * Date Written: September 24, 2015 * Course/Section: CSC 111-003W * Program Description: * This program will read and display a file. **************************************************************************************************/ package filereader; import java.util.Scanner; import java.io.File; import java.io.IOException; /** * * @author Terry */ public class FileReader { /** * * @param file the Scanner object holding the contents of the file being read * @return A String holding the contents of the file */ public static String readFile( Scanner file ) { String fileStr = ""; while (file.hasNext()) { fileStr += file.nextLine() + "\n"; } return fileStr; } /** * @param args the command line arguments * @throws IOException */ public static void main( String[] args ) throws IOException { Scanner file = new Scanner(new File("file.txt")); System.out.println("Now reading file.txt:\n"); System.out.println(readFile(file)); } }