原文 
 
import core. stdc. errno; 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		file. close ( ) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
		switch ( ex. errno) 
		{ 
			case  EPERM: 
			case  EACCES: 
				break ; 
			case  ENOENT: 
				break ; 
			default : 
				break ; 
		} 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		file. seek ( 10 ,  SEEK_SET ) ; 
		file. seek ( - 2 ,  SEEK_CUR ) ; 
		file. seek ( - 4 ,  SEEK_END ) ; 
		auto  pos =  file. tell ( ) ; 
		file. rewind ( ) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		byte[ ]  data =  [ 0x68 ,  0x65 ,  0x6c ,  0x6c ,  0x6f ] ; 
		auto  file =  File ( "test.txt" ,  "w" ) ; 
		file. rawWrite ( data) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		write ( "test.txt" ,  [ 0x68 ,  0x65 ,  0x6c ,  0x6c ,  0x6f ] ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "w" ) ; 
		file. write ( "1: Lorem ipsum\n" ) ; 
		file. writeln ( "2: Lorem ipsum" ) ; 
		file. writef ( "3: %s" ,  "Lorem ipsum\n" ) ; 
		file. writefln ( "4: %s" ,  "Lorem ipsum" ) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. file; 
import std. outbuffer; 
void  main ( string[ ]  args) 
{ 
	auto  buffer  =  new  OutBuffer ( ) ; 
	ubyte[ ]  data =  [ 0x68 ,  0x65 ,  0x6c ,  0x6c ,  0x6f ] ; 
	buffer. write ( data) ; 
	buffer. write ( ' ' ) ; 
	buffer. write ( "world" ) ; 
	try 
	{ 
		write ( "test.txt" ,  buffer. toBytes ( ) ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		byte[ ]  buffer; 
		buffer. length =  1024 ; 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		auto  data =  file. rawRead ( buffer) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  data =  cast ( byte[ ] )  read ( "test.txt" ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  data =  cast ( byte[ ] )  read ( "test.txt" ,  5 ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		foreach ( buffer;  file. byChunk ( 1024 ) ) 
		{ 
		} 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		string line; 
		while  ( ( line =  file. readln ( ) )  ! is null) 
		{ 
		} 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		char [ ]  buffer; 
		while  ( file. readln ( buffer) ) 
		{ 
		} 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. exception; 
import std. stdio; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  File ( "test.txt" ,  "r" ) ; 
		foreach ( line;  file. byLine) 
		{ 
		} 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. file; 
import std. utf; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  utf8Data  =  readText ( "test.txt" ) ; 
		auto  utf16Data =  readText! ( wstring) ( "test.txt" ) ; 
		auto  utf32Data =  readText! ( dstring) ( "test.txt" ) ; 
	} 
	catch  ( UTFException ex) 
	{ 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. exception; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		File ( "test.txt" ,  "w" ) ; 
	} 
	catch  ( ErrnoException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	if  ( exists ( "test.txt" ) ) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		rename ( "source.txt" ,  "destination.txt" ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		copy ( "source.txt" ,  "destination.txt" ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
 
import std. file; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		remove ( "test.txt" ) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. file; 
import std. stdio :  writefln; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  DirEntry ( "test.txt" ) ; 
		writefln ( "名: %s" ,  file. name) ; 
		writefln ( "是目录: %s" ,  file. isDir) ; 
		writefln ( "是文件: %s" ,  file. isFile) ; 
		writefln ( "是符号链接: %s" ,  file. isSymlink) ; 
		writefln ( "大小: %s" ,  file. size) ; 
		writefln ( "最后访问时间: %s" ,  file. timeLastAccessed) ; 
		writefln ( "最后修改时间: %s" ,  file. timeLastModified) ; 
		writefln ( "属性: %b" ,  file. attributes) ; 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. file; 
void  main ( string[ ]  args) 
{ 
	auto  file =  "test.txt" ; 
	auto  size =  100 ; 
	try 
	{ 
		if  ( file. exists ( )  &&  file. isFile ( ) ) 
		{ 
			write ( file,  read ( file,  size) ) ; 
		} 
	} 
	catch  ( FileException ex) 
	{ 
	} 
} 
import std. file; 
import std. outbuffer; 
import std. string; 
import std. zip; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  file =  new  ArchiveMember ( ) ; 
		file. name =  "test.txt" ; 
		auto  data =  new  OutBuffer ( ) ; 
		data. write ( "Lorem ipsum" ) ; 
		file. expandedData =  data. toBytes ( ) ; 
		auto  zip =  new  ZipArchive ( ) ; 
		zip. addMember ( file) ; 
		write ( "test.zip" ,  zip. build ( ) ) ; 
	} 
	catch  ( ZipException ex) 
	{ 
	} 
} 
import std. file; 
import std. zip; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  zip =  new  ZipArchive ( read ( "test.zip" ) ) ; 
		foreach ( filename,  member;  zip. directory) 
		{ 
			auto  data =  zip. expand ( member) ; 
		} 
	} 
	catch  ( ZipException ex) 
	{ 
	} 
} 
import std. file; 
import std. zlib; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  data =  compress ( "Lorem ipsum dolor sit amet" ) ; 
		write ( "test.dat" ,  data) ; 
	} 
	catch  ( ZlibException ex) 
	{ 
	} 
} 
import std. file; 
import std. zlib; 
void  main ( string[ ]  args) 
{ 
	try 
	{ 
		auto  data =  uncompress ( read ( "test.dat" ) ) ; 
	} 
	catch  ( ZlibException ex) 
	{ 
	} 
} 
import core. stdc. errno; 
import core. sys. posix. sys. stat; 
import std. conv; 
import std. string; 
void  main ( string[ ]  args) 
{ 
	auto  file   =  "test.txt" ; 
	auto  result =  chmod ( file. toStringz ( ) ,  octal! ( 666 ) ) ; 
	if  ( result !=  0 ) 
	{ 
		switch ( errno) 
		{ 
			case  EPERM: 
			case  EACCES: 
				break ; 
			case  ENOENT: 
				break ; 
			default : 
				break ; 
		} 
	} 
} 
import core. stdc. errno; 
import core. sys. posix. pwd; 
import core. sys. posix. unistd; 
import std. string; 
void  main ( string[ ]  args) 
{ 
	auto  username =  "gary" ; 
	auto  file     =  "test.txt" ; 
	auto  record   =  getpwnam ( username. toStringz ( ) ) ; 
	if  ( record ! is null) 
	{ 
		auto  user   =  record. pw_uid; 
		auto  group  =  record. pw_gid; 
		auto  result =  chown ( file. toStringz ( ) ,  user,  group) ; 
		if  ( result !=  0 ) 
		{ 
			switch ( errno) 
			{ 
				case  EPERM: 
					break ; 
				default : 
					break ; 
			} 
		} 
	} 
} 
import core. stdc. errno; 
import core. sys. posix. unistd; 
import std. string; 
void  main ( string[ ]  args) 
{ 
	auto  file   =  "test.txt" ; 
	auto  linked =  "link.txt" ; 
	auto  result =  link ( file. toStringz ( ) ,  linked. toStringz ( ) ) ; 
	if  ( result !=  0 ) 
	{ 
		switch ( errno) 
		{ 
			case  EPERM: 
			case  EACCES: 
				break ; 
			case  EEXIST: 
				break ; 
			case  ENOENT: 
			default : 
				break ; 
		} 
	} 
} 
auto  result =  link ( file. toStringz ( ) ,  linked. toStringz ( ) ) ; 
字符串
auto  result =  symlink ( file. toStringz ( ) ,  linked. toStringz ( ) ) ;