FileInfo.CreateText メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As FileInfo Dim returnValue As StreamWriter returnValue = instance.CreateText
新しい StreamWriter。


既定では、すべてのユーザーに、新しいファイルに対する完全な読み書きアクセス権が与えられます。
その他の一般的な I/O タスクまたは関連する I/O タスクの例を次の表に示します。
File.AppendText FileInfo.AppendText | |
File.Copy FileInfo.CopyTo | |
File.Move FileInfo.MoveTo | |
File.Delete FileInfo.Delete | |
CreateDirectory |

Imports System Imports System.IO Imports System.Text Public Class Test Public Shared Sub Main() Dim path As String = "c:\temp\MyTest.txt" Dim fi As FileInfo = New FileInfo(path) If fi.Exists = False Then 'Create a file to write to. Dim sw As StreamWriter = fi.CreateText() sw.WriteLine("Hello") sw.WriteLine("And") sw.WriteLine("Welcome") sw.Flush() sw.Close() End If 'Open the file to read from. Dim sr As StreamReader = fi.OpenText() Do While sr.Peek() >= 0 Console.WriteLine(sr.ReadLine()) Loop sr.Close() End Sub End Class
using System; using System.IO; class Test { public static void Main() { string path = @"c:\temp\MyTest.txt"; FileInfo fi = new FileInfo(path); if (!fi.Exists) { //Create a file to write to. using (StreamWriter sw = fi.CreateText()) { sw.WriteLine("Hello"); sw.WriteLine("And"); sw.WriteLine("Welcome"); } } //Open the file to read from. using (StreamReader sr = fi.OpenText()) { string s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } } }
using namespace System; using namespace System::IO; int main() { String^ path = "c:\\temp\\MyTest.txt"; FileInfo^ fi = gcnew FileInfo( path ); if ( !fi->Exists ) { //Create a file to write to. StreamWriter^ sw = fi->CreateText(); try { sw->WriteLine( "Hello" ); sw->WriteLine( "And" ); sw->WriteLine( "Welcome" ); } finally { if ( sw ) delete (IDisposable^)sw; } } //Open the file to read from. StreamReader^ sr = fi->OpenText(); try { String^ s = ""; while ( s = sr->ReadLine() ) { Console::WriteLine( s ); } } finally { if ( sr ) delete (IDisposable^)sr; } }
import System.*; import System.IO.*; class Test { public static void main(String[] args) { String path = "c:\\temp\\MyTest.txt"; FileInfo fi = new FileInfo(path); if (!(fi.get_Exists())) { //Create a file to write to. StreamWriter sw = fi.CreateText(); try { sw.WriteLine("Hello"); sw.WriteLine("And"); sw.WriteLine("Welcome"); } finally { sw.Dispose(); } } //Open the file to read from. StreamReader sr = fi.OpenText(); try { String s = ""; while ((s = sr.ReadLine()) != null) { Console.WriteLine(s); } } finally { sr.Dispose(); } } //main } //Test


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFileInfo.CreateText メソッドを検索する場合は、下記のリンクをクリックしてください。

- FileInfo.CreateText メソッドのページへのリンク