By using ServletContext, We can get WebContent and WebInf folder paths. Here the trick is getting ServletContext in Restful web service. Find below example program
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import javax.servlet.ServletContext; import javax.ws.rs.*; import javax.ws.rs.core.Context; @Path("readContent") public class ContentResource { /* * this class is for reading file content * REST Full web services */ /* * This method is for reading files in WebContent * @return String */ @GET @Path("webcontent") public String readWebContentFile(@Context ServletContext context, @QueryParam("file") String fileName){ String fullPath = context.getRealPath("/"+fileName); return readTextFromFile(fullPath); } /* * This method is for reading files in WEB-INF folder * @return String */ @GET @Path("webinf") public String readWebInfFile(@Context ServletContext context,@QueryParam("file") String fileName) { String fullPath = context.getRealPath("/WEB-INF/"+fileName); return readTextFromFile(fullPath); } /* * Read text from file * @param fileName * @return String */ public String readTextFromFile(String fileName) { String result = null; String line = null; try { // FileReader reads text files in the default encoding. FileReader fileReader = new FileReader(fileName); // Always wrap FileReader in BufferedReader. BufferedReader bufferedReader = new BufferedReader(fileReader); String text = ""; while((line = bufferedReader.readLine()) != null) { text += "\n"+line; } result = text; // Always close files. bufferedReader.close(); } catch(FileNotFoundException ex) { result = "Unable to open file"; } catch(IOException ex) { result = "Error reading file"; } return result; } }
Now its the time when you must come here and read all the web content files. And also come and read the webinf file due to its assignment help website and hence that thing were best for that time. We think more for that time where we can do many things for that reading file.
ReplyDeleteGreat Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
JavaScript Training in Chennai
JavaScript Training in Chennai
If you happen to look for a writing help then it's better to apply to the essay writing service for help the difference between apa and mla
ReplyDeleteMuch appreciate the blog! Great site! It looks extremely good! Good job!| you are best man…! Yuri Shafranik
ReplyDeleteI am looking for some good blog sites for studying. I was searching over search engines and found your blog site
Yuri Shafranik
I am glad that I found your blog. It is very informative and you put your maximum into it.
Yuri Shafranik
I found your website via Google whilst searching for a similar subject, your website came up, it looks good. I’ve bookmarked it in my google bookmarks.
Yuri Shafranik
Hey there, You have done a fantastic job. I’ll definitely dig it and personally suggest it to my friends. I am confident they will be benefited from this web site
ReplyDeleteYuri Shafranik
It is my pleasure to say something about the author. He did deep a awesome job
Yuri Shafranik
I’m usually blogging and I actually appreciate your content. The article has genuinely peaks my interest. I’m going to bookmark your web page and maintain checking for new details. I am looking for some good blog sites for studying. I was searching over search engines and found your blog site. Well, I like your high-quality blog site design plus your posting abilities. Keep doing it.
Yuri Shafranik
Great post. Articles that have meaningful and insightful comments are more enjoyable, at least to me. It’s interesting to read what other people thought and how it relates to them or their clients, as their perspective could possibly help you in the future.
Yuri Shafranik
I think this is one of the most significant pieces of information for me. And I’m glad read your article. Thank you for sharing!
ReplyDeleteYuri Shafranik
This article have all information that someone can easily grab Yuri Shafranik
I have never seen such a great article in my life. Good work Yuri Shafranik
You prescribe the subject in very well manners Yuri Shafranik
While most employers believe they have a responsibility for the health and wellbeing of their workforce, 4 in 10 employers do not feel this responsibility extends to their employees’ MAURICE ROUSSETY FINANCIAL financial wellbeing.
ReplyDeleteOn a day-to-day level, the top drivers of poor MAURICE FINANCIAL financial health include worries about the everyday costs of living, like paying for groceries and utilities; having or getting into debt; threats to job security,
ReplyDelete