Hello Iam trying to read text file from a JSP page.I kept the text file in the same directory of jsp.But it is not able to locate the file. System is giving file not found exceptio, I tried the same code in an application .The its working fine Can anybody help me regards Suneesh Code which i used in jsp...... <% com.StringReplace str1=new com.StringReplace(); String str=""; try{ java.io.File file =new java.io.File(register.txt); StringBuffer message=new StringBuffer(); BufferedReader br=new BufferedReader(new FileReader(file)); while((str=br.readLine())!=null) { int i=str.indexOf("<UserName>"); if(i!=-1) { str=str1.replaceString(i, 10, str, "suneesh"); } int j=str.indexOf("<Password>"); if(j!=-1) { str=str1.replaceString(j, 10, str, "suneesh"); } message.append(str+"\n");
hi suneesh Please give the absolute path of the file, as while compiling the jsp file, it won't be able to get the location of the file. try giving the path. HTH MB
there is a (semi)related thread here Basically, the 'default directory' is not what you think it is. You are assuming it is the directory where the JSP is, but it isn't. The other thread shows how to place a file in the web-inf/classes directory (or somewhere else on the web app classpath - NOT the machine classpath, they are different ) and load it dynamically. It is better not to hard-code file paths since it will make your application non-portable. Dave