How to read a file in java?

2.24K viewsJava
0

How to read a file in java – by using FileInputStream

Changed status to publish
Add a Comment
0

Use below snippet and try .

 

public  String readFile(String fileWithPath) throws IOException{
		FileInputStream inputStream = new FileInputStream(fileWithPath);
		String readTotalFile = null;
		    try {
		    	readTotalFile = IOUtils.toString(inputStream);
			} 
		 finally {
		    inputStream.close();
		}
		    return readTotalFile;
	}

 

Changed status to publish
Add a Comment
Write your answer.