Thursday, 23 March 2017

Reading a Text file using java code

How to read a text file using java code?

Here it is.

Full code available at -

The class -,  reads a text file and displays its contents, making the best use of IO weapon - FileInputStream.



public class ReadTextFile {

public static void main(String[] args) {

String myExcelPath = "sample";


private static void textReader(String myTextPath) {

FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(myTextPath);
int c;
while ((c = != -1) {
System.out.print((char) c);

if (fileInputStream != null) {
} catch (Exception e1) {


Happy Coding!!

Featured post

JAVA based project, that can be used to hit DB using JDBC, from WSO2 ESB

Hi Buddies, Here is a small project that will enable you to hit MySQL DB using WSO2 ESB -

Popular Posts