Java – Reading a File at once

\Z is the EOF (End of File) Symbol. When set as delimiter the Scanner will read the fill until the EOF Flag is reached.


package com.pwn.nio;

import java.util.Scanner;

public class ReadingFileAtOnce {

	public static void main(String[] args) {
		File f = new File("c://install//instructions.txt");
		try (Scanner scanner = new Scanner(f)) {
			String content = scanner.useDelimiter("\\Z").next();
		} catch (FileNotFoundException e) {


This is sample Instructions File


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s