• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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....
0
shragi
Asked:
shragi
2 Solutions
 
CEHJCommented:
Use
File f = new File(filelocation, "testing.txt");
PrintWriter out1 = new PrintWriter(new FileOutputStream(f);

Open in new window

0
 
shragiAuthor Commented:
@CEHJ

its working but what could be reason....

does linux never supports string concatination....
0
 
DangerousJeffCommented:
I believe the issue is the use of different slashes to denote directory's in the different OSs
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rrzCommented:
CEHJ and DangerousJeff are both right. CEHJ has shown you the easiest way because with that method java takes care of the file separator for you.  You could also use a static field of File object.
http://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html#separator 
For example, for your code, we would use  
new_filelocation = filelocation + File.separator  + "testing.txt";
0
 
CEHJCommented:
>>does linux never supports string concatination....

You're using a platform-specific separator - no need
0
 
objectsCommented:
>             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
0
 
CEHJCommented:
:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now