Solved

different names in linux and windows...

Posted on 2011-02-16
7
314 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 97
login form jsp example 2 25
Run Secure WMI query from CentOS 5 32
How to mount nfs share on this CentOS server? 6 26
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

772 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