Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
suo4.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 2k
Category:
CSharp
Development Platform:
Others
- // suo3.cs
- // 示例文件:cscs.txt
- using System;
- using System.IO;
- // 建立类文件
- // 就好像是一个数组一样
- public class FileByteArray
- {
- //建立一个流
- Stream stream;
- //用FileStream类实现对字符流的输入
- public FileByteArray(string fileName)
- {
- stream = new FileStream(fileName, FileMode.Open);
- }
- //当使用流文件结束后要关闭流
- public void Close()
- {
- stream.Close();
- stream = null;
- }
- // Indexer to provide read/write access to the file.
- public byte this[long index] // long is a 64-bit integer
- {
- // 读取一个字节 然后返回它
- get
- {
- byte[] buffer = new byte[1];
- stream.Seek(index, SeekOrigin.Begin);
- stream.Read(buffer, 0, 1);
- return buffer[0];
- }
- // 写入一个字节
- set
- {
- byte[] buffer = new byte[1] {value};
- stream.Seek(index, SeekOrigin.Begin);
- stream.Write(buffer, 0, 1);
- }
- }
- // 得到流的总长度
- public long Length
- {
- get
- {
- return stream.Seek(0, SeekOrigin.End);
- }
- }
- }
- // Demonstrate the FileByteArray class.
- // Reverses the bytes in a file.
- public class Reverse
- {
- public static void Main(String[] args)
- {
- // 检测这个文本文件是否存在
- if (args.Length == 0)
- {
- Console.WriteLine("indexer <filename>");
- return;
- }
- //将文本文件转到字节数组内
- FileByteArray file = new FileByteArray(args[0]);
- long len = file.Length;
- // 交换有为的字节达到翻转的效果
- for (long i = 0; i < len / 2; ++i)
- {
- byte t;
- //file索引器交换数的位置
- t = file[i];
- file[i] = file[len - i - 1];
- file[len - i - 1] = t;
- }
- file.Close();
- }
- }