forked from R3D9477/haxe-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
55 lines (40 loc) · 1.27 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package;
import sys.io.File;
class Main {
public static function main () {
var f_name = "ascii_file.txt";
//----------------------------------------------------------------------
trace("--- Writing ASCII file ---");
var f_out = File.write(f_name, false);
f_out.writeString("this is being written into the file\n");
f_out.writeString("this line includes a number: " + 123.312 + "\n");
f_out.close();
//----------------------------------------------------------------------
trace("--- Reading ASCII file ---");
var f_cont = File.getContent(f_name);
Sys.println("File content:\n" + f_cont);
//----------------------------------------------------------------------
trace("--- Reading ASCII file line by line ---");
var f_in = File.read(f_name, false);
try {
var i = 0;
while(true) {
var str = f_in.readLine();
Sys.println("> line" + (++i) + ": " + str);
}
}
catch(ex: haxe.io.Eof) { }
f_in.close();
//----------------------------------------------------------------------
trace("--- Reading ASCII file symbol by symbol ---");
var f_in = File.read(f_name, false);
try {
while(true) {
Sys.print(f_in.readString(1));
Sys.sleep(.1);
}
}
catch(ex: haxe.io.Eof) { }
f_in.close();
}
}