View Problem

Read the contents of a file into a string

ExpandDiskEdit
ruby
file = File.new("Solution108.rb")
whole_file = file.read
DiskEdit
csharp .Net 2.0 or later
string contents = System.IO.File.ReadAllText("filename.txt");
DiskEdit
clojure
(slurp "/tmp/foobar")
ExpandDiskEdit
fsharp
let file = new FileStream("test.txt", FileMode.Open)
let buffer = new String((new BinaryReader(file)).ReadChars(Convert.ToInt32(file.Length)))
ExpandDiskEdit
fsharp
let stream = new StreamReader("test.txt")
let buffer = stream.ReadToEnd()
ExpandDiskEdit
fsharp
let buffer = File.ReadAllText("test.txt")
ExpandDiskEdit
cpp C++/CLI .NET 2.0
IO::FileStream^ file; String^ buffer;

try
{
file = gcnew IO::FileStream("test.txt", IO::FileMode::Open);
buffer = gcnew String((gcnew IO::BinaryReader(file))->ReadChars(file->Length));
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
IO::StreamReader^ stream; String^ buffer;

try
{
stream = gcnew IO::StreamReader("test.txt");
buffer = stream->ReadToEnd();
}
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ buffer = IO::File::ReadAllText("test.txt");

Submit a new solution for ruby, csharp, clojure, fsharp ...
There are 14 other solutions in additional languages (erlang, fantom, groovy, haskell ...)