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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumanta123
    New Member
    • Dec 2008
    • 34

    #1

    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 http://127.0.0.1:81/help/Subject of Issue.txt which is right.
    But in jsp in try block when pass SubjectofIssue path that time it is
    showing SubjectofIssue) ;);//http:\127.0.0.1 :81\help\Subjec t of Issue.txt

    So the error comming in jsp page.

    Please look at my error log.

    SubjectofIssue http://127.0.0.1:81/help/Subject of Issue.txt
    stdout: exception in getting connectionhttp: \127.0.0.1:81\h elp\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.
    Regards
    Sumanta

    quote:
    Code:
     
    --------------------------------------------------------------------------------
     
    ItsPropertiesNT.properties
    ---------------------------
    SubjectofIssue=http://127.0.0.1:81/help/Subject of Issue.txt
     
    x.jsp
    --------------------------
    <%
    String SubjectofIssue = null;
    ResourceBundle bundle = null;
    if(Config.serverType != null && "NT".equals(Config.serverType))
    {
    bundle = PropertyResourceBundle.getBundle("ItsPropertiesNT");
     
    }
     
    if(bundle != null)
    {
    SubjectofIssue = bundle.getString("SubjectofIssue");
    out.println(SubjectofIssue="+SubjectofIssue);//http://127.0.0.1:81/help/Subject of Issue.txt
    }
     
    %>
    <%
    try{
    System.out.println("SubjectofIssue"+SubjectofIssue);//http:\127.0.0.1:81\help\Subject of Issue.txt
    String theBR;
    File fin=new File(SubjectofIssue);
    FileReader fr=new FileReader(fin);
    BufferedReader br=new BufferedReader(fr);
    theBR=br.readLine();
    String[] theSplit=theBR.split(",");
    for(int i=0;i<theSplit.length;i++)
    out.print("<option value=\"" + theSplit[i] +
    "\">" + theSplit[i] + "</option>");
    // out.print("</select>");
     
    }catch(Exception Ex){
    System.out.println("exception in getting connection"+Ex.getMessage());
    }
    %>
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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,

    Jos

    Comment

    • sumanta123
      New Member
      • Dec 2008
      • 34

      #3
      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(SubjectofI ssue);//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.

      Regards
      Sumanta

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        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,

        Jos

        Comment

        • sumanta123
          New Member
          • Dec 2008
          • 34

          #5
          Dear JosAHSir,
          According to your advise in the properties file

          ItsPropertiesNT .properties
          ---------------------------
          SubjectofIssue= Subject of Issue.txt

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


          Could you please advise for the needful.

          Thanks in Advance.

          Regards
          Sumanta Panda

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            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"

            Comment

            • sumanta123
              New Member
              • Dec 2008
              • 34

              #7
              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.

              Regards
              Sumanta Panda.

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                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.getServl etContext(). Then with the context you simply call the method getRealPath(Str ing path) to get the required path. So in your JSP you should do
                [code=java]
                config.getServl etContext().get RealPath(pathFr omPropertiesFil e);
                [/code]
                In the properties file you now simply store the path as "/help/Subject of Issue.txt".

                Comment

                Working...