FileIO 클래스

정의

IStorageFile 형식의 개체로 표시되는 파일을 읽고 쓰는 도우미 메서드를 제공합니다.

public ref class FileIO abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class FileIO final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class FileIO
Public Class FileIO
상속
Object Platform::Object IInspectable FileIO
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

파일 액세스 샘플에서는 WriteTextAsync(파일, 콘텐츠)를 사용하여 파일에 텍스트를 쓰는 방법을 보여 줍니다.

try
{
    if (file != null)
    {
        await FileIO.WriteTextAsync(file, "Swift as a shadow");
    }
}
catch (FileNotFoundException)
{
    // For example, handle file not found
}
try
{
    if (file)
    {
        co_await FileIO::WriteTextAsync(file, L"Swift as a shadow");
    }
}
catch (hresult_error const& ex)
{
    if (ex.code() == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
    {
        // For example, handle file not found
    }
}

예제에서 는 file 쓸 파일을 나타내는 StorageFile 을 포함하는 지역 변수입니다.

WriteTextAsync 메서드에는 반환 값이 없지만 예제와 같이 텍스트가 파일에 기록된 후에도 추가 작업을 수행할 수 있습니다. 파일 액세스 샘플에서는 ReadTextAsync(file)를 사용하여 파일에서 텍스트를 읽는 방법도 보여 줍니다.

try
{
    if (file != null)
    {
        string fileContent = await FileIO.ReadTextAsync(file);
    }
}
catch (FileNotFoundException)
{
    // For example, handle file not found
}
try
{
    if (file)
    {
        hstring fileContent = co_await FileIO::ReadTextAsync(file);
    }
}
catch (hresult_error const& ex)
{
    if (ex.code() == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
    {
        // For example, handle file not found
    }
}

예제에서 는 file 읽을 파일을 나타내는 StorageFile 을 포함하는 지역 변수입니다.

ReadTextAsync가 완료되면 변수는 fileContent 파일의 내용을 텍스트 문자열로 가져옵니다. 그런 다음 콘텐츠를 적절하게 처리할 수 있습니다.

설명

이 클래스는 정적이며 인스턴스화할 수 없습니다. 대신 메서드를 직접 호출합니다.

앱에서 액세스할 수 있는 위치에 대한 자세한 내용은 파일 액세스 권한을 참조하세요.

파일을 읽고 쓰는 방법을 알아보려면 파일 만들기, 쓰기 및 읽기를 참조하세요.

메서드

AppendLinesAsync(IStorageFile, IIterable<String>)

지정된 파일에 텍스트 줄을 추가합니다.

AppendLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일에 텍스트 줄을 추가합니다.

AppendTextAsync(IStorageFile, String)

지정된 파일에 텍스트를 추가합니다.

AppendTextAsync(IStorageFile, String, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일에 텍스트를 추가합니다.

ReadBufferAsync(IStorageFile)

지정된 파일의 내용을 읽고 버퍼를 반환합니다.

ReadLinesAsync(IStorageFile)

지정된 파일의 내용을 읽고 텍스트 줄을 반환합니다.

ReadLinesAsync(IStorageFile, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일의 내용을 읽고 텍스트 줄을 반환합니다.

ReadTextAsync(IStorageFile)

지정된 파일의 내용을 읽고 텍스트를 반환합니다.

ReadTextAsync(IStorageFile, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일의 내용을 읽고 텍스트를 반환합니다.

WriteBufferAsync(IStorageFile, IBuffer)

버퍼의 데이터를 지정된 파일에 씁니다.

WriteBytesAsync(IStorageFile, Byte[])

지정된 파일에 데이터 바이트 배열을 씁니다.

WriteLinesAsync(IStorageFile, IIterable<String>)

지정된 파일에 텍스트 줄을 씁니다.

WriteLinesAsync(IStorageFile, IIterable<String>, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일에 텍스트 줄을 씁니다.

WriteTextAsync(IStorageFile, String)

지정된 파일에 텍스트를 씁니다.

WriteTextAsync(IStorageFile, String, UnicodeEncoding)

지정된 문자 인코딩을 사용하여 지정된 파일에 텍스트를 씁니다.

적용 대상