3 Replies Latest reply on Jun 16, 2014 5:03 PM by rp0428

    java with OS help

    2679840

      Using windows machine.

      My application is using the HttpServletRequest --> getPathTranslated() method.

      The above is returning the path with backslashes in it.

      My teamates are using mac and the getPathTranslated() for them it's returning the path with forward slashes in it.

      Does the OS used matters for this? or the JRE used could be different matters?

       

      Please help.

        • 1. Re: java with OS help
          gimbal2

          Of course it matters. Each OS has different filesystem rules and the Java runtime is designed to adapt to that; that's the whole point behind a virtual machine after all, to be able to interface with the host environment in a portable way. Hence the Mac version of the Java runtime is returning different results than the Windows Runtime version, yet your code only has to call getPathTranslated() and it magically works on Windows, Linux and Mac without having to care which one it is.

           

          Check out the File.separatorChar constant to see it in writing.

           

          http://docs.oracle.com/javase/7/docs/api/java/io/File.html#separatorChar

          • 2. Re: java with OS help
            2679840

            Thanks, for the response.

             

            That makes more sense now. Our application is checking for the '/' and doing some manipulation and was failing for me as the windows is returning the '\\' as the separator. The application is in prod and working fine but, failing on my local machine. Now it's clear why it's failing.

            • 3. Re: java with OS help
              rp0428
              Our application is checking for the '/' and doing some manipulation and was failing for me as the windows is returning the '\\' as the separator.

              Your application needs to do what Java does and check for the actual separator character being used.