Solved

different names in linux and windows...

Posted on 2011-02-16
7
313 Views
Last Modified: 2012-05-11

       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
Comment
Question by:shragi
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 34910337
Use
File f = new File(filelocation, "testing.txt");
PrintWriter out1 = new PrintWriter(new FileOutputStream(f);

Open in new window

0
 

Author Comment

by:shragi
ID: 34910630
@CEHJ

its working but what could be reason....

does linux never supports string concatination....
0
 
LVL 4

Expert Comment

by:DangerousJeff
ID: 34910667
I believe the issue is the use of different slashes to denote directory's in the different OSs
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 27

Assisted Solution

by:rrz
rrz earned 100 total points
ID: 34910900
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 34911359
>>does linux never supports string concatination....

You're using a platform-specific separator - no need
0
 
LVL 92

Expert Comment

by:objects
ID: 34911481
>             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
 
LVL 86

Expert Comment

by:CEHJ
ID: 34914657
:)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now