brainfrz icon

Untitled

brainfrz | PRO | 09/24/15 10:56:39 PM UTC | 0 ⭐ | 775 👁️ | Never ⏰ | []
Java |

1.35 KB

|

None

|

0 👍

/

0 👎

/**************************************************************************************************
 *  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));
    }
    
}

Comments