View Problem

Read the contents of a file into a string

DiskEdit
python
contents = open('myFile.txt', 'rt').read()
ExpandDiskEdit
ruby
file = File.new("Solution108.rb")
whole_file = file.read
ExpandDiskEdit
java
String text = FileUtils.readFileToString(new File("Solution109.java"), "UTF-8");
ExpandDiskEdit
java
RandomAccessFile raf = null; byte[] buffer; String text = null;

try
{
raf = new RandomAccessFile("Solution399.java", "r");
buffer = new byte[(int)raf.length()]; raf.read(buffer);
text = new String(buffer);
}
ExpandDiskEdit
php >= 4.3.0
$file_contents = file_get_contents("file.txt");

Submit a new solution for python, ruby, java, or php
There are 13 other solutions in additional languages (cpp, erlang, fsharp, groovy ...)