Peedroca
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ### System.IO.Stream A Stream classe e suas classes derivadas fornecem uma exibição genérica desses diferentes tipos de entrada e saída e isolam o programador dos detalhes específicos do sistema operacional e dos dispositivos subjacentes. Fluxos envolvem estas três operações fundamentais: - **Você pode ler de fluxos**. A leitura é a transferência de dados de um fluxo para uma estrutura de dados, como uma matriz de bytes. - **Você pode gravar em fluxos**. A gravação é a transferência de dados de uma estrutura de dados para um fluxo. - **Os fluxos podem dar suporte à busca**. A busca refere-se à consulta e à modificação da posição atual em um fluxo. A funcionalidade de busca depende do tipo de armazenamento de backup que um fluxo tem. Por exemplo, os fluxos de rede não têm um conceito unificado de uma posição atual e, portanto, normalmente não dão suporte à busca. ### System.IO.StreamReader - StreamReader tem o padrão de codificação **UTF-8**, a menos que especificado de outra forma, em vez de padronizar para a página de código ANSI para o sistema atual. - Por padrão, um StreamReader não é **thread-safe**. ```csharp= using (StreamWriter sw = new StreamWriter("text2.txt")) { sw.NewLine = ";"; sw.WriteLine("Hel{0}", "lo"); // Hello; sw.WriteLine("Hello World 2"); // Hello;Hello World 2; sw.Write(true); // Hello;Hello World 2;True sw.Write("Hello World 2"); // Hello;Hello World 2;TrueHello World 2 sw.WriteLine("Hello World 2"); // Hello;Hello World 2;TrueHello World 2Hello World 2; var text = new char[5] { 'P', 'E', 'D', 'R', 'O' }; sw.Write(text, 2, 3); // Hello;Hello World 2;TrueHello World 2Hello World 2;DRO } ``` ### System.IO.StreamWriter - Não é Thread-Safe. - UTF8. - Async e sync. ``` Hello; World; ``` > text.txt <br/> ```csharp= using (StreamReader sr = new StreamReader("text.txt")) { var r = (Char)sr.Read(); Console.WriteLine(r); // H var line = sr.ReadLine(); Console.WriteLine(line); // ello; char[] buffer = new char[5]; var iavel = sr.ReadBlock(buffer, 0, 2); Console.WriteLine(buffer); // Wo Console.WriteLine(iavel); // 2 } ``` ### System.IO.FileStream A classe é usada para executar o funcionamento básico da leitura e escrita de arquivos do sistema operacional. A classe FileStream ajuda na leitura, escrita e fechamento de arquivos. ```csharp= using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace FileStream_CreateFile { class Program { static void Main(string[] args) { FileStream fs = new FileStream("D:\\csharpfile.txt", FileMode.Create); fs.Close(); Console.Write("File has been created and the Path is D:\\csharpfile.txt"); Console.ReadKey(); } } } ``` ### System.IO.StringReader Ele permite você ler uma string sincronizadamente ou assincronicamente. Você pode ler um caracter com Read() ou ler uma linha com ReadLine(). ```csharp= using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace StringReader_Class { class Program { static void Main(string[] args) { string text = @"AuAuAuAuAU"; using (StringReader reader = new StringReader(text)) { int count = 0; string line; while ((line = reader.ReadLine()) != null) { count++; Console.WriteLine("Line {0}: {1}", count, line); } } Console.ReadKey(); } } } ``` ### System.IO.StringWriter StringWriter classe é derivado da classe e é usado principalmente para manipular string em vez de arquivos. Permite que você escreva uma sequencia de string sincronizadamente ou assincronicamente. ```csharp= using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace StringWriter_Class { class Program { static void Main(string[] args) { string text = "Hello. This is Line 1 \n Hello. This is Line 2 \nHello This is Line 3"; StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); //Guarda a informação no StringBuilder writer.WriteLine(text); writer.Close(); StringReader reader = new StringReader(sb.ToString()); //Confere se chegou no fim do arquivo while (reader.Peek() > -1) { Console.WriteLine(reader.ReadLine()); } } } } ``` ### System.IO.MemoryStream A classe `MemoryStream` cria fluxos que têm a memória como armazenamento de apoio, em vez de disco ou conexão de rede. `MemoryStream` encapsula dados armazenados como uma matriz de bytes não assinada. Os dados encapsulados podem ser acessados diretamente na memória. Os fluxos de memória podem reduzir a necessidade de buffers e arquivos temporários em um aplicativo. * A posição atual de um fluxo é a posição em que ocorre a próxima operação de leitura ou gravação. * A posição atual pode ser recuperada ou definida por meio do método System.IO.MemoryStream.Seek (System.Int64, System.IO.SeekOrigin). * Quando uma nova instância de MemoryStream é criada, a posição atual é definida como zero. Se um objeto MemoryStream for serializado em um arquivo de recurso, ele será, na verdade, serializado como um UnmanagedMemoryStream. Esse comportamento fornece melhor desempenho, bem como a capacidade de obter um ponteiro para os dados diretamente, sem precisar passar pelos métodos do Stream . ```csharp= using System; using System.IO; using System.Text; class Program { static void Main() { string memString = "Memory test string !!"; // convert string to stream byte[] buffer = Encoding.ASCII.GetBytes(memString); using(var ms = new MemoryStream(buffer)) { //write to file FileStream file = new FileStream("d:\\file.txt", FileMode.Create, FileAccess.Write); ms.WriteTo(file); file.Close(); ms.Close(); } } } ``` ### System.IO.BufferedStream Um buffer é um bloco de bytes na memória usado para armazenar dados em cache, reduzindo assim o número de chamadas para o sistema operacional. Os buffers melhoram o desempenho de leitura e gravação. Um buffer pode ser usado para leitura ou gravação, mas nunca ambos simultaneamente. ```csharp= using System; using System.Diagnostics; using System.IO; class Program { static void Main() { // Use BufferedStream to buffer writes to a MemoryStream. using (MemoryStream memory = new MemoryStream()) using (BufferedStream stream = new BufferedStream(memory)) { // Write a byte 5 million times. for (int i = 0; i < 5000000; i++) { stream.WriteByte(5); } } } } ``` ### System.IO.UnmanagedMemoryStream Essa classe dá suporte ao acesso à memória não gerenciada usando o modelo existente baseado em fluxo e não requer que o conteúdo na memória não gerenciada seja copiado para o heap. Um bloco de memória não gerenciada é alocado e desalocado usando a Marshal classe. ```csharp= // Note: you must compile this sample using the unsafe flag. // From the command line, type the following: csc sample.cs /unsafe using System; using System.IO; using System.Text; using System.Runtime.InteropServices; unsafe class TestWriter { static void Main() { // Create some data to read and write. byte[] message = UnicodeEncoding.Unicode.GetBytes("Here is some data."); // Allocate a block of unmanaged memory and return an IntPtr object. IntPtr memIntPtr = Marshal.AllocHGlobal(message.Length); // Get a byte pointer from the IntPtr object. byte* memBytePtr = (byte*)memIntPtr.ToPointer(); // Create an UnmanagedMemoryStream object using a pointer to unmanaged memory. var writeStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Write); // Write the data. writeStream.Write(message, 0, message.Length); // Close the stream. writeStream.Close(); // Create another UnmanagedMemoryStream object using a pointer to unmanaged memory. var readStream = new UnmanagedMemoryStream(memBytePtr, message.Length, message.Length, FileAccess.Read); // Create a byte array to hold data from unmanaged memory. byte[] outMessage = new byte[message.Length]; // Read from unmanaged memory to the byte array. readStream.Read(outMessage, 0, message.Length); // Close the stream. readStream.Close(); // Display the data to the console. Console.WriteLine(UnicodeEncoding.Unicode.GetString(outMessage)); // Free the block of unmanaged memory. Marshal.FreeHGlobal(memIntPtr); Console.ReadLine(); } } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully