1.概要
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string f2 = Path.Combine(GetFolderPath(), fileName);
File.WriteAllText(f2, "hello word!");
2 代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Collections.Immutable;
using System.Text;
using System.IO;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string fileName = "test.txt";
string f2 = Path.Combine(GetFolderPath(), fileName);
File.WriteAllText(f2, "hello word!");
Console.ReadKey();
}
static string GetFolderPath() {
return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
}
}
3.运行结果