Ejemplo n.º 1
0
    public static void Main(String[] args)
    {
        // 检查参数。
        if (args.Length != 1)
        {
            Console.WriteLine("Usage : Indexer <filename>");
            return;
        }

        // 检查文件是否存在
        if (!System.IO.File.Exists(args[0]))
        {
            Console.WriteLine("File " + args[0] + " not found.");
            return;
        }

        FileByteArray file = new FileByteArray(args[0]);
        long len = file.Length;

        // 交换文件中的字节以对其进行反转。
        for (long i = 0; i < len / 2; ++i)
        {
            byte t;

            // 请注意,为“file”变量建立索引会调用
            //  FileByteStream 类上的索引器,该索引器在文件中读取
            // 和写入字节。
            t = file[i];
            file[i] = file[len - i - 1];
            file[len - i - 1] = t;
        }

        file.Close();
    }
Ejemplo n.º 2
0
    public static void Main(String[] args)
    {
        // Check for arguments.
        if (args.Length != 1)
        {
            Console.WriteLine("Usage : Indexer <filename>");
            return;
        }

        // Check for file existence
        if (!System.IO.File.Exists(args[0]))
        {
            Console.WriteLine("File " + args[0] + " not found.");
            return;
        }

        FileByteArray file = new FileByteArray(args[0]);
        long len = file.Length;

        // Swap bytes in the file to reverse it.
        for (long i = 0; i < len / 2; ++i)
        {
            byte t;

            // Note that indexing the "file" variable invokes the
            // indexer on the FileByteStream class, which reads
            // and writes the bytes in the file.
            t = file[i];
            file[i] = file[len - i - 1];
            file[len - i - 1] = t;
        }

        file.Close();
    }