How to read a file in java?

3.73K viewsJava
0

How to read a file in java – by using FileInputStream

Manohar Changed status to publish July 7, 2019
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;
	}

 

Manohar Changed status to publish July 7, 2019
Add a Comment
Write your answer.