View Problem

Append to a file

DiskEdit
ruby
file = File.new('/tmp/test.txt', 'a+') ; file.puts 'This line appended to file!!' ; file.close()
ExpandDiskEdit
java
FileWriter fw = null;

try
{
fw = new FileWriter("test.txt", true);
fw.write("This line appended to file!");
}
ExpandDiskEdit
java
PrintWriter pw = null;

try
{
pw = new PrintWriter(new BufferedWriter(new FileWriter("test.txt", true)));
pw.print("This line appended to file!");
}
DiskEdit
perl
open($fh, '>>', $path) or die "can't open $path: $!";
print $fh "This line is appended to the file!";
close $fh;
ExpandDiskEdit
groovy
file << 'some text'
ExpandDiskEdit
scala
val fw = new FileWriter("test.txt", true) ; fw.write("This line appended to file!") ; fw.close()
DiskEdit
python
open('test.txt', 'at').write('Hello World!\n')
ExpandDiskEdit
cpp C++/CLI .NET 2.0
IO::StreamWriter^ stream;

try
{
stream = gcnew IO::StreamWriter("test.txt", true);
stream->WriteLine("This line appended to file!");
}
ExpandDiskEdit
fsharp
let stream = new StreamWriter("test.txt", true)
stream.WriteLine("This line appended to file!")
ExpandDiskEdit
erlang
Line = "This line appended to file!\n",
{ok, IODevice} = file:open("test.txt", [append]), file:write(IODevice, Line), file:close(IODevice).
ExpandDiskEdit
php
/****
* For some (security)reason I couldn't
* submit this without adding a space to
* the functionnames. Please remove it :)
****/

if ($fh = f open("file.txt", 'a')) { // a == append
f write($fh, "Append some text\n");
f close($fh);
}
DiskEdit
php PHP 5
<?php
file_put_contents('file.txt', 'a string to append', FILE_APPEND);
?>

Submit a new solution for ruby, java, perl, groovy ...