How Can I read text file in liferay?
java
Solution
In a Java string, `\` starts an escape sequence and "\r" and "\t" are escaped characters. For example "\t" is a string with the tab character. If you literally need `\t` in a string, you'll have to escape the backslash
doSomething("\\resources\\testing.txt");
or just eliminate the hassle: Java operates well when you use the forward slash as directory separator
doSomething("/resources/testing.txt");
Note that this refers to a file in the root directory of whatever drive the current path is on, it might be C:\resources\testing.txt or D:\resources\testing.txt - unless your `ReadFile` implementation manipulates the path somehow (which I leave up to your judgement). You can test this independent of Liferay, just in a command line application. The exception gets thrown way before your jsp gets displayed (I've changed the tags to flag the relevance)
This is pure Java, completely independent of Liferay.
Problem
I have tried to read a file from controller class with this code ``` ReadFile readFile = new ReadFile(); String text = readFile.readFile("\resources\testing.txt"); renderRequest.setAttribute("text", text); ``` I have fetched it from view.jsp as ``` <% String content = (String)request.getAttribute("text"); %> ``` But I am getting file not found exception. What is the way to get file content.