<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://50.77.162.165/mediawiki/skins/common/feed.css?207"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://50.77.162.165/mediawiki/index.php?feed=atom&amp;target=Frantz&amp;title=Special%3AContributions</id>
		<title>Erights - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://50.77.162.165/mediawiki/index.php?feed=atom&amp;target=Frantz&amp;title=Special%3AContributions"/>
		<link rel="alternate" type="text/html" href="http://50.77.162.165/wiki/Special:Contributions/Frantz"/>
		<updated>2026-04-24T18:22:41Z</updated>
		<subtitle>From Erights</subtitle>
		<generator>MediaWiki 1.15.5-7</generator>

	<entry>
		<id>http://50.77.162.165/wiki/Walnut/Ordinary_Programming/InputOutput</id>
		<title>Walnut/Ordinary Programming/InputOutput</title>
		<link rel="alternate" type="text/html" href="http://50.77.162.165/wiki/Walnut/Ordinary_Programming/InputOutput"/>
				<updated>2007-02-26T06:04:45Z</updated>
		
		<summary type="html">&lt;p&gt;Frantz:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Walnut|2]]&lt;br /&gt;
&lt;br /&gt;
===I/O===&lt;br /&gt;
&lt;br /&gt;
E file objects are created with the &amp;lt;file:name&amp;gt; expression (which produces a [http://www.erights.org/javadoc/java/io/File.html &amp;quot;tamed&amp;quot; Java File Object], i.e., a File object that follows capability security discipline). If you can hard-code the name, you usually do not need to use quotes (unless there is a space or another invalid url character). If the name is contained in a variable or is retrieved with a function call, you must &amp;lt;font color=&amp;quot;#FF0000&amp;quot;&amp;gt;XXX&amp;lt;/font&amp;gt; place a space between the colon and the representation of the name. If the word &amp;quot;file&amp;quot; is replaced with a single letter like &amp;quot;c&amp;quot;, the letter is assumed to be the drive letter on a Windows machine:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# E sample&lt;br /&gt;
 #File objects for hardwired files:&lt;br /&gt;
 def file1 := &amp;lt;file:myFile.txt&amp;gt;&lt;br /&gt;
 def file2 := &amp;lt;file:/home/marcs/myFile.txt&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 #Using a variable for a file name:&lt;br /&gt;
 def filePath := &amp;quot;c:\\docs\\myFile.txt&amp;quot;&lt;br /&gt;
 def file3 := &amp;lt;file&amp;gt; [filePath]&lt;br /&gt;
 &lt;br /&gt;
 #Using a single character to specify a Windows drive&lt;br /&gt;
 def file4 := &amp;lt;c:/docs/myFile.txt&amp;gt;&lt;br /&gt;
 def file5 := &amp;lt;c:\docs\myFile.txt&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in the file3 example, there is a space between the &amp;lt;file&amp;gt; and the left bracket.&lt;br /&gt;
&lt;br /&gt;
Note that in the file4 example, we used slashes, not backslashes, to separate directories on a Windows drive. ''In &amp;lt;span class=&amp;quot;e&amp;quot;&amp;gt;''E''&amp;lt;/span&amp;gt;, the slash always works as a directory separator no matter the underlying operating system. ''&lt;br /&gt;
&lt;br /&gt;
When constructing the filePath string we used double backslashes because in strings the backslash must be escaped by a backslash. A double backslash was not required in the hardwired file (file5).&lt;br /&gt;
&lt;br /&gt;
File objects can represent directories as well as simple files. Files inside the directory can be accessed by indexing using square brackets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;# E syntax&lt;br /&gt;
 def dir := &amp;lt;file:/home/marcs/dataDir/&amp;gt;&lt;br /&gt;
 def file6 := dir[&amp;quot;myFile.txt&amp;quot;]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both text files and directories work in conjunction with the &amp;quot;for&amp;quot; loop. With a directory, the loop iterates through the files in the directory. With a text file, the loop iterates through the lines of the file; each line-object is terminated with a newline ('\n') character. The lines in the loop are terminated with newline regardless of the underlying operating system, regardless of the operating system's end-of-line designation.&lt;br /&gt;
&lt;br /&gt;
Files respond to the following messages [http://www.erights.org/javadoc/java/io/File.html (see the Edoc for a complete list)].&lt;br /&gt;
&lt;br /&gt;
* exists -- returns true if the file exists&lt;br /&gt;
* deepReadOnly -- returns a file object that can be read, but not written. If the file is a directory, the readOnly nature is transitive to all files and directories reached via this object.&lt;br /&gt;
* setText(textString) -- creates the file and/or replaces the file contents with the text. When written out, the end-of-line designator is automatically converted to the local end-of-line mark for the underlying operating system. On Windows, for example, each line is automatically terminated by a cr/lf pair.&lt;br /&gt;
* getText -- returns the text from the file. Regardless of underlying operating system, the returned text uses a single newline character as the end-of-line mark.&lt;br /&gt;
* getBytes() -- returns the bytes of the file in a byte ConstList&lt;br /&gt;
* setBytes(byteList)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;stdout and stderr are both TextWriters in the E environment.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Example: recursing through a directory tree searching for a file ====&lt;br /&gt;
&lt;br /&gt;
 def findFile(targetFileName, dir) :void {&lt;br /&gt;
 &lt;br /&gt;
     def iterator(filename, file) {&lt;br /&gt;
         if (filename == targetFileName) {&lt;br /&gt;
             println(`Found $targetFileName at ${file.getPath()}`)&lt;br /&gt;
         }&lt;br /&gt;
         if (file.isDirectory()) {&lt;br /&gt;
             findFile(targetFileName, file)&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     dir.iterate(iterator)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 def ehomeDir := &amp;lt;file&amp;gt;[interp.getProps()[&amp;quot;e.home&amp;quot;]]&lt;br /&gt;
 findFile(&amp;quot;Substituter.class&amp;quot;, ehomeDir)&lt;/div&gt;</summary>
		<author><name>Frantz</name></author>	</entry>

	</feed>