<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Java_readFile</id>
	<title>Java readFile - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.theeggeadventure.com/wikimedia/index.php?action=history&amp;feed=atom&amp;title=Java_readFile"/>
	<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Java_readFile&amp;action=history"/>
	<updated>2026-05-12T21:05:35Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0-beta</generator>
	<entry>
		<id>https://www.theeggeadventure.com/wikimedia/index.php?title=Java_readFile&amp;diff=2193&amp;oldid=prev</id>
		<title>Brianegge: Created page with &#039;Reading a file into a string in Ruby is as simple as:  &lt;geshi lang=&quot;ruby&quot;&gt; File.new(&#039;foo.txt&#039;).read &lt;/geshi&gt;  Unfortunately, Java has no simple method to do the same bundled with…&#039;</title>
		<link rel="alternate" type="text/html" href="https://www.theeggeadventure.com/wikimedia/index.php?title=Java_readFile&amp;diff=2193&amp;oldid=prev"/>
		<updated>2009-08-26T02:43:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;Reading a file into a string in Ruby is as simple as:  &amp;lt;geshi lang=&amp;quot;ruby&amp;quot;&amp;gt; File.new(&amp;#039;foo.txt&amp;#039;).read &amp;lt;/geshi&amp;gt;  Unfortunately, Java has no simple method to do the same bundled with…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Reading a file into a string in Ruby is as simple as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
File.new(&amp;#039;foo.txt&amp;#039;).read&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately, Java has no simple method to do the same bundled with the JDK.  Here&amp;#039;s the equivalent Java function:&lt;br /&gt;
&amp;lt;geshi lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
	public String readFile(File file) throws IOException {&lt;br /&gt;
		BufferedReader br = new BufferedReader(new FileReader(file));&lt;br /&gt;
		String line;&lt;br /&gt;
		StringBuilder result = new StringBuilder();&lt;br /&gt;
		while ((line = br.readLine()) != null) {&lt;br /&gt;
			result.append(line);&lt;br /&gt;
			result.append(&amp;quot;\n&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
		br.close();&lt;br /&gt;
		return result.toString();&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/geshi&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Java]]&lt;br /&gt;
[[Category:Ruby]]&lt;/div&gt;</summary>
		<author><name>Brianegge</name></author>
	</entry>
</feed>