Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Read File Linewise with Java (See related posts)


Here's the class

import java.io.*;

public class MyIO {
	void printFile(String fileName) {
		BufferedReader rd;
		String line;

		try {
			rd = new BufferedReader(new FileReader(fileName));
						
			while ((line =  rd.readLine()  ) != null) {
				System.out.println(line);
			}
			rd.close();
		} catch (final IOException e) {
			System.out.println("Error reading file");
		}

	}

}



All along with an example usage:

	MyIO myIO = new MyIO();
	myIO.printFile("filename.txt");


You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts