Link to home
Create AccountLog in
Avatar of shragi
shragiFlag for India

asked on

different names in linux and windows...


       filelocation = (String)session.getAttribute("selectedfolder");
         new_filelocation = filelocation + "\\"  + "testing.txt";
            PrintWriter out1 = new PrintWriter(new FileOutputStream(new_filelocation));
                  out1.println("hi");
            
            file location is giving me the path something like
            C:/users/temp
            so new_location is
                        C:/users/temp/testing.txt

            this works well in windows i.e., a file with name testing.txt is created and i can see msg "hi"
            in that

            but in linux

            the file is created with file name temp\testing.txt
            but i can see "hi" msg in that...

            how to overcome this problem....
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of shragi

ASKER

@CEHJ

its working but what could be reason....

does linux never supports string concatination....
I believe the issue is the use of different slashes to denote directory's in the different OSs
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
>>does linux never supports string concatination....

You're using a platform-specific separator - no need
>             the file is created with file name temp\testing.txt

because the file separator in linux is a / (not a \), so it treats it as character in the filename
:)