WindowsRuntimeStreamExtensions 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Windows 스토어 앱에 대한 .NET Windows 런타임 스트림과 관리되는 스트림 간에 변환하기 위한 확장 메서드를 포함합니다.
public ref class WindowsRuntimeStreamExtensions abstract sealed
[System.Security.SecurityCritical]
public static class WindowsRuntimeStreamExtensions
[<System.Security.SecurityCritical>]
type WindowsRuntimeStreamExtensions = class
Public Module WindowsRuntimeStreamExtensions
- 상속
-
WindowsRuntimeStreamExtensions
- 특성
예제
다음 예제에서는 다음을 사용하는 방법을 보여 있습니다 AsStreamForWrite . AsStreamForRead
using System;
using System.IO;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace ExampleApplication
{
public sealed partial class BlankPage : Page
{
public BlankPage()
{
this.InitializeComponent();
}
private async void CreateButton_Click(object sender, RoutedEventArgs e)
{
StorageFile newFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("testfile.txt");
var streamNewFile = await newFile.OpenAsync(FileAccessMode.ReadWrite);
using (var outputNewFile = streamNewFile.GetOutputStreamAt(0))
{
using (StreamWriter writer = new StreamWriter(outputNewFile.AsStreamForWrite()))
{
await writer.WriteLineAsync("content for new file");
await writer.WriteLineAsync(UserText.Text);
}
}
}
private async void VerifyButton_Click(object sender, RoutedEventArgs e)
{
StorageFile openedFile = await ApplicationData.Current.LocalFolder.GetFileAsync("testfile.txt");
var streamOpenedFile = await openedFile.OpenAsync(FileAccessMode.Read);
using (var inputOpenedFile = streamOpenedFile.GetInputStreamAt(0))
{
using (StreamReader reader = new StreamReader(inputOpenedFile.AsStreamForRead()))
{
Results.Text = await reader.ReadToEndAsync();
}
}
}
}
}
Imports System.IO
Imports Windows.Storage
NotInheritable Public Class BlankPage
Inherits Page
Private Async Sub CreateButton_Click(sender As Object, e As RoutedEventArgs)
Dim newFile As StorageFile = Await ApplicationData.Current.LocalFolder.CreateFileAsync("testfile.txt")
Dim streamNewFile = Await newFile.OpenAsync(FileAccessMode.ReadWrite)
Using outputNewFile = streamNewFile.GetOutputStreamAt(0)
Using writer As StreamWriter = New StreamWriter(outputNewFile.AsStreamForWrite())
Await writer.WriteLineAsync("content for new file")
Await writer.WriteLineAsync(UserText.Text)
End Using
End Using
End Sub
Private Async Sub VerifyButton_Click(sender As Object, e As RoutedEventArgs)
Dim openedFile As StorageFile = Await ApplicationData.Current.LocalFolder.GetFileAsync("testfile.txt")
Dim streamOpenedFile = Await openedFile.OpenAsync(FileAccessMode.Read)
Using inputOpenedFile = streamOpenedFile.GetInputStreamAt(0)
Using reader As StreamReader = New StreamReader(inputOpenedFile.AsStreamForRead())
Results.Text = Await reader.ReadToEndAsync()
End Using
End Using
End Sub
End Class
다음은 이전 예제와 연결된 XAML 코드입니다.
<Page
x:Class="ExampleApplication.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ExampleApplication"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Background="{StaticResource ApplicationPageBackgroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="Provide text to write to file:"></TextBlock>
<TextBox Name="UserText" Width="400"></TextBox>
<Button Name="CreateButton" Content="Create File" Click="CreateButton_Click"></Button>
<Button Name="VerifyButton" Content="Verify Contents" Click="VerifyButton_Click"></Button>
<TextBlock Name="Results"></TextBlock>
</StackPanel>
</Page>
설명
이러한 확장 메서드는 Windows 스토어 앱을 개발하는 경우에만 사용할 수 있습니다. 이 메서드는 Windows 스토어 앱에서 스트림을 사용하는 편리한 방법을 제공합니다. 클래스의 WindowsRuntimeStreamExtensions 인스턴스를 만들지 않습니다. 대신 인터페이스 및 <xref:Windows.Storage.Streams.IInputStream> 클래스의 <xref:Windows.Storage.Streams.IOutputStream> 인스턴스에서 이러한 메서드를 Stream 사용합니다.
WindowsRuntimeStreamExtensions 클래스에는 관리되는 Stream 개체를 Windows 런타임 스트림으로 변환하는 두 가지 메서드가 포함되어 있습니다.
WindowsRuntimeStreamExtensions 클래스에는 Windows 런타임 스트림을 Stream 개체로 변환하기 위한 세 가지 오버로드된 메서드가 포함되어 있습니다.
.NET Framework 4.5.1부터 WindowsRuntimeStreamExtensions 클래스에는 스트림을 Windows 런타임 <xref:Windows.Storage.Streams.RandomAccessStream> 변환하는 메서드가 포함되어 있습니다.
메서드
| Name | Description |
|---|---|
| AsInputStream(Stream) |
Windows 스토어 앱용 .NET의 관리되는 스트림을 Windows 런타임의 입력 스트림으로 변환합니다. |
| AsOutputStream(Stream) |
Windows 스토어 앱용 .NET의 관리되는 스트림을 Windows 런타임의 출력 스트림으로 변환합니다. |
| AsRandomAccessStream(Stream) |
지정된 스트림을 임의 액세스 스트림으로 변환합니다. |
| AsStream(IRandomAccessStream, Int32) |
지정된 버퍼 크기를 사용하여 Windows 런타임 임의 액세스 스트림을 Windows 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |
| AsStream(IRandomAccessStream) |
Windows 런타임 임의 액세스 스트림을 Windows 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |
| AsStreamForRead(IInputStream, Int32) |
지정된 버퍼 크기를 사용하여 Windows 런타임 입력 스트림을 Windows 8.x 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |
| AsStreamForRead(IInputStream) |
Windows 런타임 입력 스트림을 Windows 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |
| AsStreamForWrite(IOutputStream, Int32) |
지정된 버퍼 크기를 사용하여 Windows 런타임 출력 스트림을 Windows 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |
| AsStreamForWrite(IOutputStream) |
Windows 런타임 출력 스트림을 Windows 8.x 스토어 앱의 .NET 관리되는 스트림으로 변환합니다. |