This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
How to write into a file under linux environment? The file is going to be written under /home/testing/temp with a file as "newFile.txt" How do I proceed? [ April 27, 2008: Message edited by: Gopu Akraju ]
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
Joined: Jan 13, 2008
I tried as below: It works perfectly fine under windows environment. How do I it in Linux.
Below is the code which works under windows: outDir is from a Config file
The above code is working perfectly fine in windows and outFile gets written under c:\testing\temp with a file name for eg 2008-04-20_11-41-06.txt
In the linux machine if I change the config file as below: But a file name becomes \home\testing\temp\2008-04-27_09-39-48.txt under \home\testing\temp directory. And tehre is an error in opening too. What is wrong with hte approach? I have not worked with Linus before. Thanks. [ April 28, 2008: Message edited by: Gopu Akraju ]
To make your program work on Windows as well as Linux, you should use the constant File.separator instead of hard-coding / or \ in your program
Or always use a '/', which works under Windows, too. Could fail under some other arcane operating system, of course.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus