Solved

different names in linux and windows...

Posted on 2011-02-16
7
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 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