サーチ…


パラメーター

パラメータ詳細
文字列パス確認するファイルのパス。 (相対的または完全修飾された)

備考

ファイルが存在する場合はtrue、そうでない場合はfalseを返します。

VB WriteAllText

Imports System.IO

Dim filename As String = "c:\path\to\file.txt"
File.WriteAllText(filename, "Text to write" & vbCrLf)

VB StreamWriter

Dim filename As String = "c:\path\to\file.txt"
If System.IO.File.Exists(filename) Then
    Dim writer As New System.IO.StreamWriter(filename)
    writer.Write("Text to write" & vbCrLf) 'Add a newline
    writer.close()
End If

C#StreamWriter

using System.Text;
using System.IO;

string filename = "c:\path\to\file.txt";
//'using' structure allows for proper disposal of stream.
using (StreamWriter writer = new StreamWriter(filename"))
{
    writer.WriteLine("Text to Write\n");
}

C#WriteAllText()

using System.IO;
using System.Text;

string filename = "c:\path\to\file.txt";
File.writeAllText(filename, "Text to write\n");

C#File.Exists()

using System;
using System.IO;
                
public class Program
{
    public static void Main()
    {
        string filePath = "somePath";
    
        if(File.Exists(filePath))
        {
            Console.WriteLine("Exists");
        }
        else
        {
            Console.WriteLine("Does not exist");    
        }
    }
}

三項演算子でも使用できます。

Console.WriteLine(File.Exists(pathToFile) ? "Exists" : "Does not exist");


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow