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 ]
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 ]
Writing to a file in Java is the same in Windows, Linux or any other operating system on which you can run Java; the only difference is the way in which names of files and directories are specified.
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:
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
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, the permaculture playing cards