View Problem

Read the contents of a file into a string

DiskEdit
python
contents = open('myFile.txt', 'rt').read()
DiskEdit
csharp .Net 2.0 or later
string contents = System.IO.File.ReadAllText("filename.txt");
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
fantom
contents := File(`file.text`).readAllStr

Submit a new solution for python, csharp, java, or fantom
There are 18 other solutions in additional languages (clojure, cpp, erlang, fsharp ...)