这是保存文本文件的绝对路径。现在我想转换成相对路径。
<a class="navbar-brand" href="index.jsp"> <%
String jspPath = "C:\\Users\\Farshid\\workspace\\STPT\\WebContent\\file\\title.txt"; //this is my absolute path.
BufferedReader reader = new BufferedReader(new FileReader(jspPath));
StringBuilder sb = new StringBuilder();
String line;
line = reader.readLine();%> <%=line%></a>
现在我如何在jsp中改变相对路径?这是我的项目目录图片。
答案 0 :(得分:-1)
尝试:
String path = getServletConfig().getServletContext().getRealPath("/file/title.txt");
BufferedReader reader = new BufferedReader(new FileReader(path));