19 lines
475 B
Text
19 lines
475 B
Text
fn file_size(filename: String) throws -> i64 {
|
|
mut result = 0
|
|
mut file = File::open_for_reading(filename)
|
|
mut buffer = [0u8; 1024] // Size of buffer is arbitrary
|
|
while true {
|
|
let read_bytes = file.read(buffer)
|
|
if read_bytes == 0 {
|
|
break
|
|
}
|
|
result += read_bytes as! i64
|
|
}
|
|
return result
|
|
}
|
|
|
|
|
|
fn main() {
|
|
println("{}", file_size(filename: "input.txt"))
|
|
println("{}", file_size(filename: "/input.txt"))
|
|
}
|