2024年最新猿创征文|【(4),2024年最新大数据开发通用流行框架大全

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

    // Asynchronously read back the written data.
    fStream.Position = 0;
    asyncResult = fStream.BeginRead(
        tempState.ReadArray, 0 , tempState.ReadArray.Length,
        new AsyncCallback(EndReadCallback), tempState);

    // Concurrently do other work, such as
    // logging the write operation.
}

// When BeginRead is finished reading data from the file, the
// EndReadCallback method is called to end the asynchronous
// read operation and then verify the data.
static void EndReadCallback(IAsyncResult asyncResult)
{
    State tempState = (State)asyncResult.AsyncState;
    int readCount = tempState.FStream.EndRead(asyncResult);

    int i = 0;
    while(i < readCount)
    {
        if(tempState.ReadArray[i] != tempState.WriteArray[i++])
        {
            Console.WriteLine("Error writing data.");
            tempState.FStream.Close();
            return;
        }
    }
    Console.WriteLine("The data was written to {0} and verified.",
        tempState.FStream.Name);
    tempState.FStream.Close();

    // Signal the main thread that the verification is finished.
    tempState.ManualEvent.Set();
}

// Maintain state information to be passed to
// EndWriteCallback and EndReadCallback.
class State
{
    // fStream is used to read and write to the file.
    FileStream fStream;

    // writeArray stores data that is written to the file.
    byte[] writeArray;

    // readArray stores data that is read from the file.
    byte[] readArray;

    // manualEvent signals the main thread
    // when verification is complete.
    ManualResetEvent manualEvent;

    public State(FileStream fStream, byte[] writeArray,
        ManualResetEvent manualEvent)
    {
        this.fStream   = fStream;
        this.writeArray = writeArray;
        this.manualEvent = manualEvent;
        readArray = new byte[writeArray.Length];
    }

    public FileStream FStream
    { get{ return fStream; } }

    public byte[] WriteArray
    { get{ return writeArray; } }

    public byte[] ReadArray
    { get{ return readArray; } }

    public ManualResetEvent ManualEvent
    { get{ return manualEvent; } }
}

}


###### FileStream(String, FileMode)


使用指定的路径和创建模式初始化 [FileStream](https://bbs.csdn.net/topics/618545628) 类的新实例。



public FileStream (string path, System.IO.FileMode mode);


**参数**



> 
> `path`
> 
> 
> [String](https://bbs.csdn.net/topics/618545628)
> 
> 
> 当前 `FileStream` 对象将封装的文件的相对路径或绝对路径。
> 
> 
> `mode`
> 
> 
> [FileMode](https://bbs.csdn.net/topics/618545628)
> 
> 
> 用于确定文件的打开或创建方式的枚举值之一。
> 
> 
> 


**示例**


下面的代码示例演示了如何按字节将数据写入文件,然后验证是否已正确写入数据。



using System;
using System.IO;

class FStream
{
static void Main()
{
const string fileName = “Test#@@#.dat”;

    // Create random data to write to the file.
    byte[] dataArray = new byte[100000];
    new Random().NextBytes(dataArray);

    using(FileStream
        fileStream = new FileStream(fileName, FileMode.Create))
    {
        // Write the data to the file, byte by byte.
        for(int i = 0; i < dataArray.Length; i++)
        {
            fileStream.WriteByte(dataArray[i]);
        }

        // Set the stream position to the beginning of the file.
        fileStream.Seek(0, SeekOrigin.Begin);

        // Read and verify the data.
        for(int i = 0; i < fileStream.Length; i++)
        {
            if(dataArray[i] != fileStream.ReadByte())
            {
                Console.WriteLine("Error writing data.");
                return;
            }
        }
        Console.WriteLine("The data was written to {0} " +
            "and verified.", fileStream.Name);
    }
}

}


##### ♊ 属性


###### CanRead 当在派生类中重写时,获取指示当前流是否支持读取的值



public abstract bool CanRead { get; }


**示例**



using System;
using System.IO;

class TestRW
{
public static void Main(String[] args)
{
FileStream fs = new FileStream(“MyFile.txt”, FileMode.OpenOrCreate, FileAccess.Read);
if (fs.CanRead && fs.CanWrite)
{
Console.WriteLine(“MyFile.txt can be both written to and read from.”);
}
else if (fs.CanRead)
{
Console.WriteLine(“MyFile.txt is not writable.”);
}
}
}


###### CanWrite 当在派生类中重写时,获取指示当前流是否支持写入功能的值



public abstract bool CanWrite { get; }


**示例**



using System;
using System.IO;

class TestRW
{
public static void Main(String[] args)
{
FileStream fs = new FileStream(“MyFile.txt”, FileMode.OpenOrCreate,
FileAccess.Write);
if (fs.CanRead && fs.CanWrite) {
Console.WriteLine(“MyFile.txt can be both written to and read from.”);
}
else if (fs.CanWrite) {
Console.WriteLine(“MyFile.txt is writable.”);
}
}
}
//This code outputs “MyFile.txt is writable.”
//To get the output message “MyFile.txt can be both written to and read from.”,
//change the FileAccess parameter to ReadWrite in the FileStream constructor.


###### Length 当在派生类中重写时,获取流长度(以字节为单位)



public abstract long Length { get; }


##### ♌ 常用方法


###### Close() 关闭当前流并释放与之关联的所有资源(如套接字和文件句柄)



public virtual void Close ();



> 
> 注意:此方法调用 [Dispose](https://bbs.csdn.net/topics/618545628) ,指定 `true` 以释放所有资源。 不需要专门调用 [Close](https://bbs.csdn.net/topics/618545628) 方法。 请确保 [Stream](https://bbs.csdn.net/topics/618545628) 已正确释放每个对象。 可以 [Stream](https://bbs.csdn.net/topics/618545628) `using` `Using` 在 Visual Basic) 中 (或块中声明对象,以确保释放流及其所有资源,或者可以显式调用 [Dispose](https://bbs.csdn.net/topics/618545628) 方法。
> 
> 
> 


###### CopyTo(Stream) 从当前流中读取字节并将其写入到另一流中



public void CopyTo (System.IO.Stream destination);


**参数**



> 
> `destination`
> 
> 
> **Stream**
> 
> 
> 当前流的内容将复制到的流。
> 
> 
> 


**示例**


下面的示例将的内容复制 [FileStream](https://bbs.csdn.net/topics/618545628) 到 [MemoryStream](https://bbs.csdn.net/topics/618545628) 中。



// Create the streams.
MemoryStream destination = new MemoryStream();

using (FileStream source = File.Open(@“c:\temp\data.dat”,
FileMode.Open))
{

Console.WriteLine("Source length: {0}", source.Length.ToString());

// Copy source to destination.
source.CopyTo(destination);

}

Console.WriteLine(“Destination length: {0}”, destination.Length.ToString());


###### CopyTo(Stream, Int32) 使用指定的缓冲区大小,从当前流中读取字节并将其写入到另一流中



public virtual void CopyTo (System.IO.Stream destination, int bufferSize);


**参数**



> 
> `destination`
> 
> 
> **Stream**
> 
> 
> 当前流的内容将复制到的流。
> 
> 
> `bufferSize`
> 
> 
> **Int**
> 
> 
> 缓冲区的大小。 此值必须大于零。 默认大小为 81920。
> 
> 
> 


###### CopyToAsync(Stream) 从当前流中异步读取字节并将其写入到另一个流中



public System.Threading.Tasks.Task CopyToAsync (System.IO.Stream destination);


**参数**



> 
> `destination`
> 
> 
> **Stream**
> 
> 
> 当前流的内容将复制到的流。
> 
> 
> 


**示例**


下面的示例演示如何使用两个 [FileStream](https://bbs.csdn.net/topics/618545628) 对象将文件从一个目录异步复制到另一个目录。 [FileStream](https://bbs.csdn.net/topics/618545628) 类是从 [Stream](https://bbs.csdn.net/topics/618545628) 类派生的。 请注意, [Click](https://bbs.csdn.net/topics/618545628) 控件的事件处理程序 [Button](https://bbs.csdn.net/topics/618545628) 使用修饰符标记, `async` 因为它调用异步方法



using System;
using System.Threading.Tasks;
using System.Windows;
using System.IO;

namespace WpfApplication
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        string StartDirectory = @"c:\Users\exampleuser\start";
        string EndDirectory = @"c:\Users\exampleuser\end";

        foreach (string filename in Directory.EnumerateFiles(StartDirectory))
        {
            using (FileStream SourceStream = File.Open(filename, FileMode.Open))
            {
                using (FileStream DestinationStream = File.Create(EndDirectory + filename.Substring(filename.LastIndexOf('\\'))))
                {
                    await SourceStream.CopyToAsync(DestinationStream);
                }
            }
        }
    }
}

}



> 
> [CopyToAsync](https://bbs.csdn.net/topics/618545628)方法使你可以在不阻塞主线程的情况下执行占用大量资源的 i/o 操作。
> 
> 
> 


###### Dispose() 释放由 Stream 使用的所有资源



public void Dispose ();


###### Read(Byte[], Int32, Int32) 当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数



public abstract int Read (byte[] buffer, int offset, int count);


**参数**



> 
> `buffer`
> 
> 
> [Byte](https://bbs.csdn.net/topics/618545628)[]
> 
> 
> 字节数组。 当此方法返回时,此缓冲区包含指定的字符数组,此数组中 `offset` 和 (`offset` + `count` - 1) 之间的值被从当前源中读取的字节所替换。
> 
> 
> `offset`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> `buffer` 中的从零开始的字节偏移量,从此处开始存储从当前流中读取的数据。
> 
> 
> `count`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 要从当前流中最多读取的字节数。
> 
> 
> 


**返回**



> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 读入缓冲区中的总字节数。 如果很多字节当前不可用,则总字节数可能小于请求的字节数;如果已到达流结尾,则为零 (0)。
> 
> 
> 


**示例**


下面的示例演示如何使用 [Read](https://bbs.csdn.net/topics/618545628) 读取数据块。



using System;
using System.IO;

public class Block
{
public static void Main()
{
Stream s = new MemoryStream();
for (int i = 0; i < 122; i++)
{
s.WriteByte((byte)i);
}
s.Position = 0;

    // Now read s into a byte buffer with a little padding.
    byte[] bytes = new byte[s.Length + 10];
    int numBytesToRead = (int)s.Length;
    int numBytesRead = 0;
    do
    {
        // Read may return anything from 0 to 10.
        int n = s.Read(bytes, numBytesRead, 10);
        numBytesRead += n;
        numBytesToRead -= n;
    } while (numBytesToRead > 0);
    s.Close();

    Console.WriteLine("number of bytes read: {0:d}", numBytesRead);
}

}



> 
> 使用 [CanRead](https://bbs.csdn.net/topics/618545628) 属性确定当前实例是否支持读取。 使用 [ReadAsync](https://bbs.csdn.net/topics/618545628) 方法从当前流异步读取。
> 
> 
> 此方法的实现从当前流中读取最大字节 `count` 数,并存储从 `buffer` 开始的字节 `offset` 。 流中的当前位置按读取的字节数进行高级;但是,如果发生异常,则流中的当前位置保持不变。 实现返回读取的字节数。 在没有任何数据可用时,实现将一直阻止,直到至少可以读取一个字节的数据。 [Read](https://bbs.csdn.net/topics/618545628) 仅在流中没有更多数据且预期没有更多数据(例如关闭套接字或文件结尾) (返回 0) 。 即使尚未到达流的末尾,实现也能够返回比请求的更少的字节。
> 
> 
> 


###### ReadAsync(Byte[], Int32, Int32) 从当前流异步读取字节序列,并将流中的位置提升读取的字节数



public System.Threading.Tasks.Task ReadAsync (byte[] buffer, int offset, int count);


**参数**



> 
> `buffer`
> 
> 
> [Byte](https://bbs.csdn.net/topics/618545628)[]
> 
> 
> 要写入数据的缓冲区。
> 
> 
> `offset`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> `buffer` 中的字节偏移量,从该偏移量开始写入从流中读取的数据。
> 
> 
> `count`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 最多读取的字节数。
> 
> 
> 


**返回**



> 
> [Task](https://bbs.csdn.net/topics/618545628)<[Int32](https://bbs.csdn.net/topics/618545628)>
> 
> 
> 表示异步读取操作的任务。 `TResult` 参数的值包含读入缓冲区的总字节数。 如果当前可用字节数少于所请求的字节数,则该结果值可小于所请求的字节数;如果已到达流结尾时,则为 0(零)。
> 
> 
> 


**示例**


下面的示例演示如何以异步方式从文件读取。 该示例使用 [FileStream](https://bbs.csdn.net/topics/618545628) 类,该类派生自 [Stream](https://bbs.csdn.net/topics/618545628) 类。



using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;

namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        string filename = @"c:\Temp\userinputlog.txt";
        byte[] result;

        using (FileStream SourceStream = File.Open(filename, FileMode.Open))
        {
            result = new byte[SourceStream.Length];
            await SourceStream.ReadAsync(result, 0, (int)SourceStream.Length);
        }

        UserInput.Text = System.Text.Encoding.ASCII.GetString(result);
    }
}

}


###### ReadByte() 从文件中读取一个字节,并将读取位置提升一个字节



public override int ReadByte ();


**返回**



> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 强制转换为 [Int32](https://bbs.csdn.net/topics/618545628) 的字节;或者如果已到达流的末尾,则为 -1。
> 
> 
> 


**示例**


下面的代码示例演示了如何按字节将数据写入文件,然后验证是否已正确写入数据。



using System;
using System.IO;

class FStream
{
static void Main()
{
const string fileName = “Test#@@#.dat”;

    // Create random data to write to the file.
    byte[] dataArray = new byte[100000];
    new Random().NextBytes(dataArray);

    using(FileStream
        fileStream = new FileStream(fileName, FileMode.Create))
    {
        // Write the data to the file, byte by byte.
        for(int i = 0; i < dataArray.Length; i++)
        {
            fileStream.WriteByte(dataArray[i]);
        }

        // Set the stream position to the beginning of the file.
        fileStream.Seek(0, SeekOrigin.Begin);

        // Read and verify the data.
        for(int i = 0; i < fileStream.Length; i++)
        {
            if(dataArray[i] != fileStream.ReadByte())
            {
                Console.WriteLine("Error writing data.");
                return;
            }
        }
        Console.WriteLine("The data was written to {0} " +
            "and verified.", fileStream.Name);
    }
}

}


###### Write(Byte[], Int32, Int32) 当在派生类中重写时,向当前流中写入字节序列,并将此流中的当前位置提升写入的字节数



public abstract void Write (byte[] buffer, int offset, int count);


**参数**



> 
> `buffer`
> 
> 
> [Byte](https://bbs.csdn.net/topics/618545628)[]
> 
> 
> 字节数组。 此方法将 `count` 个字节从 `buffer` 复制到当前流。
> 
> 
> `offset`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> `buffer` 中的从零开始的字节偏移量,从此处开始将字节复制到当前流。
> 
> 
> `count`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 要写入当前流的字节数。
> 
> 
> 



> 
> 使用 [CanWrite](https://bbs.csdn.net/topics/618545628) 属性确定当前实例是否支持写入。 使用 [WriteAsync](https://bbs.csdn.net/topics/618545628) 方法异步写入当前流。
> 
> 
> 如果写入操作成功,则流中的位置将按写入的字节数前进。 如果发生异常,则流中的位置保持不变。
> 
> 
> 


###### WriteAsync(Byte[], Int32, Int32) 将字节序列异步写入当前流,并将流的当前位置提升写入的字节数



public System.Threading.Tasks.Task WriteAsync (byte[] buffer, int offset, int count);


**参数**



> 
> `buffer`
> 
> 
> [Byte](https://bbs.csdn.net/topics/618545628)[]
> 
> 
> 从中写入数据的缓冲区。
> 
> 
> `offset`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> `buffer` 中的从零开始的字节偏移量,从此处开始将字节复制到该流。
> 
> 
> `count`
> 
> 
> [Int32](https://bbs.csdn.net/topics/618545628)
> 
> 
> 最多写入的字节数。
> 
> 
> 


**返回**



> 
> [Task](https://bbs.csdn.net/topics/618545628)
> 
> 
> 表示异步写入操作的任务。
> 
> 
> 


**示例**


下面的示例演示如何异步写入文件。 该示例使用 [FileStream](https://bbs.csdn.net/topics/618545628) 类,该类派生自 [Stream](https://bbs.csdn.net/topics/618545628) 类。



using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.IO;

namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        UnicodeEncoding uniencoding = new UnicodeEncoding();
        string filename = @"c:\Users\exampleuser\Documents\userinputlog.txt";

        byte[] result = uniencoding.GetBytes(UserInput.Text);

        using (FileStream SourceStream = File.Open(filename, FileMode.OpenOrCreate))
        {
            SourceStream.Seek(0, SeekOrigin.End);
            await SourceStream.WriteAsync(result, 0, result.Length);
        }
    }
}

}


###### WriteByte(Byte) 一个字节写入文件流中的当前位置



public override void WriteByte (byte value);


**参数**



> 
> `value`
> 
> 
> [Byte](https://bbs.csdn.net/topics/618545628)
> 
> 
> 要写入流的字节。
> 
> 
> 


**示例**


下面的代码示例演示如何将数据以字节字节形式写入文件,然后验证数据是否写入正确。



using System;
using System.IO;

class FStream
{
static void Main()
{
const string fileName = “Test#@@#.dat”;

    // Create random data to write to the file.
    byte[] dataArray = new byte[100000];
    new Random().NextBytes(dataArray);

    using(FileStream
        fileStream = new FileStream(fileName, FileMode.Create))
    {
        // Write the data to the file, byte by byte.
        for(int i = 0; i < dataArray.Length; i++)
        {
            fileStream.WriteByte(dataArray[i]);
        }

        // Set the stream position to the beginning of the file.
        fileStream.Seek(0, SeekOrigin.Begin);

        // Read and verify the data.
        for(int i = 0; i < fileStream.Length; i++)
        {
            if(dataArray[i] != fileStream.ReadByte())
            {
                Console.WriteLine("Error writing data.");
                return;
            }
        }
        Console.WriteLine("The data was written to {0} " +
            "and verified.", fileStream.Name);
    }
}

}


###### Flush() 清除此流的缓冲区,使得所有缓冲数据都写入到文件中



public override void Flush ();


**示例**


此代码示例是为 方法提供的较大示例的 [Lock](https://bbs.csdn.net/topics/618545628) 一部分。



// Update the file.
case ‘W’:
try
{
fileStream.Seek(textLength,
SeekOrigin.Begin);
fileStream.Read(
readText, textLength - 1, byteCount);
tempString = new String(
uniEncoding.GetChars(
readText, textLength - 1, byteCount));
recordNumber = int.Parse(tempString) + 1;
fileStream.Seek(
textLength, SeekOrigin.Begin);
fileStream.Write(uniEncoding.GetBytes(
recordNumber.ToString()),
0, byteCount);
fileStream.Flush();
Console.WriteLine(
“Record has been updated.”);
}



> 
> 此方法重写 [Stream.Flush](https://bbs.csdn.net/topics/618545628)。
> 
> 
> 调用 方法 [FileStream.Flush](https://bbs.csdn.net/topics/618545628) 时,也会刷新操作系统 I/O 缓冲区。
> 
> 
> 除非显式调用或释放 对象,否则不会刷新 [Flush](https://bbs.csdn.net/topics/618545628) 流的编码器。 设置为 [StreamWriter.AutoFlush](https://bbs.csdn.net/topics/618545628) `true` 表示数据从缓冲区刷新到流,但不刷新编码器状态。 这允许编码器保留其状态 (部分字符) 以便它可以正确编码下一个字符块。 这种情况会影响 UTF8 和 UTF7,其中某些字符只能在编码器收到相邻字符后进行编码。
> 
> 
> 由于缓冲区可用于读取或写入, [Flush()](https://bbs.csdn.net/topics/618545628) 因此 执行以下两个函数:
> 
> 
> * 以前写入缓冲区的任何数据都复制到文件,并且缓冲区被清除,但编码器状态除外。
> * 如果 为 且数据以前从文件复制到缓冲区进行读取,则文件中当前位置将减少缓冲区中未读 [BufferedStream.CanSeek](https://bbs.csdn.net/topics/618545628) `true` 字节数。 然后清除缓冲区。
> 
> 
> 


###### FlushAsync() 异步清除此流的所有缓冲区并导致所有缓冲数据都写入基础设备中



public System.Threading.Tasks.Task FlushAsync ();


**返回**



> 
> [Task](https://bbs.csdn.net/topics/618545628)
> 
> 
> 表示异步刷新操作的任务。
> 
> 
> 


###### Lock(Int64, Int64) 防止其他进程读取或写入 FileStream



[System.Runtime.Versioning.UnsupportedOSPlatform(“ios”)]
[System.Runtime.Versioning.UnsupportedOSPlatform(“macos”)]
[System.Runtime.Versioning.UnsupportedOSPlatform(“tvos”)]
public virtual void Lock (long position, long length);


**参数**



> 
> `position`
> 
> 
> [Int64](https://bbs.csdn.net/topics/618545628)
> 
> 
> 要锁定的范围的起始处。 此参数的值必须大于或等于零 (0)。
> 
> 
> `length`
> 
> 
> [Int64](https://bbs.csdn.net/topics/618545628)
> 
> 
> 要锁定的范围。
> 
> 
> 


**示例**


下面的代码示例演示如何锁定文件的一部分,以便另一个进程无法访问该文件的该部分,即使它具有对文件的读/写访问权限。 在不同的命令窗口中同时运行程序,并使用不同的控制台输入选项进行调查。



using System;
using System.IO;
using System.Text;

class FStreamLock
{
static void Main()
{
UnicodeEncoding uniEncoding = new UnicodeEncoding();
string lastRecordText =
"The last processed record number was: ";
int textLength = uniEncoding.GetByteCount(lastRecordText);
int recordNumber = 13;
int byteCount =
uniEncoding.GetByteCount(recordNumber.ToString());
string tempString;

    using(FileStream fileStream = new FileStream(
        "Test#@@#.dat", FileMode.OpenOrCreate,
        FileAccess.ReadWrite, FileShare.ReadWrite))
    {
        // Write the original file data.
        if(fileStream.Length == 0)
        {
            tempString =
                lastRecordText + recordNumber.ToString();
            fileStream.Write(uniEncoding.GetBytes(tempString),
                0, uniEncoding.GetByteCount(tempString));
        }

        // Allow the user to choose the operation.
        char consoleInput = 'R';
        byte[] readText = new byte[fileStream.Length];
        while(consoleInput != 'X')
        {
            Console.Write(
                "\nEnter 'R' to read, 'W' to write, 'L' to " +
                "lock, 'U' to unlock, anything else to exit: ");

            if((tempString = Console.ReadLine()).Length == 0)
            {
                break;
            }
            consoleInput = char.ToUpper(tempString[0]);
            switch(consoleInput)
            {
                // Read data from the file and
                // write it to the console.
                case 'R':
                    try
                    {
                        fileStream.Seek(0, SeekOrigin.Begin);
                        fileStream.Read(
                            readText, 0, (int)fileStream.Length);
                        tempString = new String(
                            uniEncoding.GetChars(
                            readText, 0, readText.Length));
                        Console.WriteLine(tempString);
                        recordNumber = int.Parse(
                            tempString.Substring(
                            tempString.IndexOf(':') + 2));
                    }

                    // Catch the IOException generated if the
                    // specified part of the file is locked.
                    catch(IOException e)
                    {
                        Console.WriteLine("{0}: The read " +
                            "operation could not be performed " +
                            "because the specified part of the " +
                            "file is locked.",
                            e.GetType().Name);
                    }
                    break;

                // Update the file.
                case 'W':
                    try
                    {
                        fileStream.Seek(textLength,
                            SeekOrigin.Begin);
                        fileStream.Read(
                            readText, textLength - 1, byteCount);
                        tempString = new String(
                            uniEncoding.GetChars(
                            readText, textLength - 1, byteCount));
                        recordNumber = int.Parse(tempString) + 1;
                        fileStream.Seek(
                            textLength, SeekOrigin.Begin);
                        fileStream.Write(uniEncoding.GetBytes(
                            recordNumber.ToString()),
                            0, byteCount);
                        fileStream.Flush();
                        Console.WriteLine(
                            "Record has been updated.");
                    }

                    // Catch the IOException generated if the
                    // specified part of the file is locked.
                    catch(IOException e)
                    {
                        Console.WriteLine(
                            "{0}: The write operation could not " +
                            "be performed because the specified " +
                            "part of the file is locked.",
                            e.GetType().Name);
                    }
                    break;

                // Lock the specified part of the file.
                case 'L':
                    try
                    {

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

       fileStream.Flush();
                        Console.WriteLine(
                            "Record has been updated.");
                    }

                    // Catch the IOException generated if the
                    // specified part of the file is locked.
                    catch(IOException e)
                    {
                        Console.WriteLine(
                            "{0}: The write operation could not " +
                            "be performed because the specified " +
                            "part of the file is locked.",
                            e.GetType().Name);
                    }
                    break;

                // Lock the specified part of the file.
                case 'L':
                    try
                    {

[外链图片转存中…(img-6Qp9KV5t-1715661383802)]
[外链图片转存中…(img-RUVgSiRK-1715661383803)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 19
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值