471,852 Members | 919 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

filename, directory name, or volume label syntax is error in the try catch

Dear Sir
when i am getting the value from properties file the
the path showing of Issue.txt which is right.
But in jsp in try block when pass SubjectofIssue path that time it is
showing SubjectofIssue););//http:\\help\Subject of Issue.txt

So the error comming in jsp page.

Please look at my error log.

SubjectofIssue of Issue.txt
stdout: exception in getting connectionhttp:\\help\Subject of Issue.txt (The filename, directory name, or volume label syntax is incorrect)

Could you please tell me the reason why such an error i am geting in jsp inside the tryblock.

Thanks in Advance.

Expand|Select|Wrap|Line Numbers
  2. --------------------------------------------------------------------------------
  4. ItsPropertiesNT.properties
  5. ---------------------------
  6. SubjectofIssue= of Issue.txt
  8. x.jsp
  9. --------------------------
  10. <%
  11. String SubjectofIssue = null;
  12. ResourceBundle bundle = null;
  13. if(Config.serverType != null && "NT".equals(Config.serverType))
  14. {
  15. bundle = PropertyResourceBundle.getBundle("ItsPropertiesNT");
  17. }
  19. if(bundle != null)
  20. {
  21. SubjectofIssue = bundle.getString("SubjectofIssue");
  22. out.println(SubjectofIssue="+SubjectofIssue);// of Issue.txt
  23. }
  25. %>
  26. <%
  27. try{
  28. System.out.println("SubjectofIssue"+SubjectofIssue);//http:\\help\Subject of Issue.txt
  29. String theBR;
  30. File fin=new File(SubjectofIssue);
  31. FileReader fr=new FileReader(fin);
  32. BufferedReader br=new BufferedReader(fr);
  33. theBR=br.readLine();
  34. String[] theSplit=theBR.split(",");
  35. for(int i=0;i<theSplit.length;i++)
  36. out.print("<option value=\"" + theSplit[i] +
  37. "\">" + theSplit[i] + "</option>");
  38. // out.print("</select>");
  40. }catch(Exception Ex){
  41. System.out.println("exception in getting connection"+Ex.getMessage());
  42. }
  43. %>
Jan 2 '09 #1
7 11313
11,448 Expert 8TB
I don't quite understand your question but that url most certainly isn't a valid file name; you should use the URL and/or URLConnection classes for that, not the File class.

kind regards,

Jan 2 '09 #2
Dear JosAH Sir,
You are right.Means i read the data from properties file.And kept it in a variable.

Instead of hard coded that in the file
File fin=new File("C:/Project/Sun/https-ITS/webapps/https-ITS/help/Subject of Issue.txt");//Which is getting right value.

But if i am using File fin=new File(SubjectofIssue);//SubjectofIssue which i store the properties file data which given error.

Could you please sir tell me the syntax how we use URL here
File fin=new File(URL);

Please sir,Advise me for the needful.

Thanks in Advance.

Jan 2 '09 #3
11,448 Expert 8TB
But if that file is stored on a local file system, why don't you simply change your ItsPropertiesNT.properties file? You don't need a URL for that. A file name is enough.

kind regards,

Jan 2 '09 #4
Dear JosAHSir,
According to your advise in the properties file

SubjectofIssue=Subject of Issue.txt

Now in jsp
SubjectofIssue = bundle.getString("SubjectofIssue");//It is getting the path
But if we pass the path in the file it is not working.
File fin=new File(SubjectofIssue);

Could you please advise for the needful.

Thanks in Advance.

Sumanta Panda
Jan 7 '09 #5
13,262 8TB
What happens if you specify the full path of the file in your properties file instead of just the file name? Remember the JSP runs in the webapplication's context. You need to get to the servlet context first which in your case is "C:/Project/Sun/https-ITS/webapps/https-ITS". Then you need to give the path including the folder where you have put it, which is "/help/Subject of Issue.txt"
Jan 7 '09 #6
Dear r035198x Sir,
I agreed it is working.But if it is in our local machine then it will work.
Suppose if we keep the file in server machine then how it will work.
Could you please advise me for the needful.
Thanks in advance.

Sumanta Panda.
Jan 7 '09 #7
13,262 8TB
Om the server machine you no longer have the path "C:/Project/Sun/https-ITS/webapps". You need to first get the path where the jsps and servlets are running from and then get the path to your file from there. This path is (sometimes) called the servlet context. To get it you use the utility method config.getServletContext(). Then with the context you simply call the method getRealPath(String path) to get the required path. So in your JSP you should do
Expand|Select|Wrap|Line Numbers
  1. config.getServletContext().getRealPath(pathFromPropertiesFile);
In the properties file you now simply store the path as "/help/Subject of Issue.txt".
Jan 8 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Krazitchek | last post: by
2 posts views Thread by Technical Group | last post: by
8 posts views Thread by Dmitry Klymenko | last post: by
1 post views Thread by Andrew | last post: by
8 posts views Thread by Michael Robertson | last post: by
1 post views Thread by =?Utf-8?B?QnJpYW4=?= | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.