Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,15 +1,5 @@
|
|||
import std.stdio;
|
||||
|
||||
int main() {
|
||||
auto from = File("input.txt", "rb");
|
||||
scope(exit) from.close();
|
||||
|
||||
auto to = File("output.txt", "wb");
|
||||
scope(exit) to.close();
|
||||
|
||||
foreach(buffer; from.byChunk(new ubyte[4096*1024])) {
|
||||
to.rawWrite(buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
void main() {
|
||||
import std.file;
|
||||
auto data = std.file.read("input.txt");
|
||||
std.file.write("output.txt", data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
import tango.io.device.File;
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto from = new File("input.txt");
|
||||
auto to = new File("output.txt", File.WriteCreate);
|
||||
to.copy(from).close;
|
||||
from.close;
|
||||
int main() {
|
||||
auto from = File("input.txt", "rb");
|
||||
scope(exit) from.close();
|
||||
|
||||
auto to = File("output.txt", "wb");
|
||||
scope(exit) to.close();
|
||||
|
||||
foreach(buffer; from.byChunk(new ubyte[4096*1024])) {
|
||||
to.rawWrite(buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import tango.io.device.File;
|
|||
|
||||
void main()
|
||||
{
|
||||
auto from = new File("input.txt");
|
||||
auto to = new File("output.txt", File.WriteCreate);
|
||||
to.copy(new File("input.txt")).close;
|
||||
to.copy(from).close;
|
||||
from.close;
|
||||
}
|
||||
|
|
|
|||
7
Task/File-input-output/D/file-input-output-5.d
Normal file
7
Task/File-input-output/D/file-input-output-5.d
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import tango.io.device.File;
|
||||
|
||||
void main()
|
||||
{
|
||||
auto to = new File("output.txt", File.WriteCreate);
|
||||
to.copy(new File("input.txt")).close;
|
||||
}
|
||||
9
Task/File-input-output/DCL/file-input-output.dcl
Normal file
9
Task/File-input-output/DCL/file-input-output.dcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$ open input input.txt
|
||||
$ open /write output output.txt
|
||||
$ loop:
|
||||
$ read /end_of_file = done input line
|
||||
$ write output line
|
||||
$ goto loop
|
||||
$ done:
|
||||
$ close input
|
||||
$ close output
|
||||
16
Task/File-input-output/Elixir/file-input-output-1.elixir
Normal file
16
Task/File-input-output/Elixir/file-input-output-1.elixir
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
defmodule FileReadWrite do
|
||||
def copy(path,new_path) do
|
||||
case File.read(path) do
|
||||
# In case of success, write to the new file
|
||||
{:ok, body} ->
|
||||
# Can replace with :write! to generate an error upon failure
|
||||
File.write(new_path,body)
|
||||
# If not successful, raise an error
|
||||
{:error,reason} ->
|
||||
# Using Erlang's format_error to generate error string
|
||||
:file.format_error(reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
FileReadWrite.copy("input.txt","output.txt")
|
||||
1
Task/File-input-output/Elixir/file-input-output-2.elixir
Normal file
1
Task/File-input-output/Elixir/file-input-output-2.elixir
Normal file
|
|
@ -0,0 +1 @@
|
|||
File.cp!("input.txt", "output.txt")
|
||||
10
Task/File-input-output/Rust/file-input-output-1.rust
Normal file
10
Task/File-input-output/Rust/file-input-output-1.rust
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
fn main() {
|
||||
let mut file = File::open("input.txt").unwrap();
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data).unwrap();
|
||||
let mut file = File::create("output.txt").unwrap();
|
||||
file.write_all(&data).unwrap();
|
||||
}
|
||||
28
Task/File-input-output/Rust/file-input-output-2.rust
Normal file
28
Task/File-input-output/Rust/file-input-output-2.rust
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::Path;
|
||||
use std::{env, fmt, process};
|
||||
|
||||
fn main() {
|
||||
let files: Vec<_> = env::args_os().skip(1).take(2).collect();
|
||||
|
||||
if files.len() != 2 {
|
||||
exit_err("Both an input file and output file are required", 1);
|
||||
}
|
||||
|
||||
copy(&files[0], &files[1]).unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)));
|
||||
}
|
||||
|
||||
fn copy<P: AsRef<Path>>(infile: P, outfile: P) -> io::Result<()> {
|
||||
let mut vec = Vec::new();
|
||||
|
||||
Ok(try!(File::open(infile)
|
||||
.and_then(|mut i| i.read_to_end(&mut vec))
|
||||
.and_then(|_| File::create(outfile))
|
||||
.and_then(|mut o| o.write_all(&vec))))
|
||||
}
|
||||
|
||||
fn exit_err<T: fmt::Display>(msg: T, code: i32) -> ! {
|
||||
writeln!(&mut io::stderr(), "ERROR: {}", msg).expect("Could not write to stdout");
|
||||
process::exit(code);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
extern mod std;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let input_file = &Path("input.txt");
|
||||
let input = io::read_whole_file_str(input_file);
|
||||
match input {
|
||||
Err(e) => fail!(e),
|
||||
Ok(_) => {}
|
||||
}
|
||||
|
||||
let output_file = &Path("output.txt");
|
||||
let output = io::file_writer(output_file, [io::Create, io::Truncate]);
|
||||
match output {
|
||||
Err(e) => fail!(e),
|
||||
Ok(_) => {}
|
||||
}
|
||||
|
||||
output.unwrap().write_str(input.unwrap());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue