using System;
using System.IO;
using System.Text;

namespace Document.Bll
{
/// <summary>
/// Summary description for fileinfo.
/// </summary>
public class fileinfo
{
public fileinfo()
{
//
// TODO: Add constructor logic here
//
}
获取某目录下的所有文件(包括子目录下文件)的数量

获取某目录下的所有文件(包括子目录下文件)的大小

读取文件

写文件

System.IO.Path
}
}
2.简单的txt文件操作:
//检查文件,如果文件不存在则创建
private void ExistsFile(string FilePath)
{
if(!File.Exists(FilePath))
File.Create(FilePath);
}
private void Button2_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//读取文件
StreamReader sr = new StreamReader(MapPath("weather.txt"), System.Text.Encoding.Default);
string input = sr.ReadToEnd();
sr.Close();
input = input.Replace("\r\n", "<br>").Replace("\n", "<br>");
this.TextBox1.Text = input;
}

private void Button1_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//写入文件
StreamWriter sr = new StreamWriter(MapPath("weather.txt"),false,System.Text.Encoding.Default);
sr.Write(this.TextBox1.Text);
sr.Close();
}

简单的txt文件操作:
//检查文件,如果文件不存在则创建
private void ExistsFile(string FilePath)
{
if(!File.Exists(FilePath))
File.Create(FilePath);
}
private void Button2_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//读取文件
StreamReader sr = new StreamReader(MapPath("weather.txt"), System.Text.Encoding.Default);
string input = sr.ReadToEnd();
sr.Close();
input = input.Replace("\r\n", "<br>").Replace("\n", "<br>");
this.TextBox1.Text = input;
}

private void Button1_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//写入文件
StreamWriter sr = new StreamWriter(MapPath("weather.txt"),false,System.Text.Encoding.Default);
sr.Write(this.TextBox1.Text);
sr.Close();
}
using System.IO;
using System.Text;
namespace Document.Bll
{
/// <summary>
/// Summary description for fileinfo.
/// </summary>
public class fileinfo
{
public fileinfo()
{
//
// TODO: Add constructor logic here
//
}
获取某目录下的所有文件(包括子目录下文件)的数量
获取某目录下的所有文件(包括子目录下文件)的大小
读取文件
写文件
System.IO.Path
}
}2.简单的txt文件操作:
//检查文件,如果文件不存在则创建
private void ExistsFile(string FilePath)
{
if(!File.Exists(FilePath))
File.Create(FilePath);
}
private void Button2_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//读取文件
StreamReader sr = new StreamReader(MapPath("weather.txt"), System.Text.Encoding.Default);
string input = sr.ReadToEnd();
sr.Close();
input = input.Replace("\r\n", "<br>").Replace("\n", "<br>");
this.TextBox1.Text = input;
}
private void Button1_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//写入文件
StreamWriter sr = new StreamWriter(MapPath("weather.txt"),false,System.Text.Encoding.Default);
sr.Write(this.TextBox1.Text);
sr.Close();
}
简单的txt文件操作:
//检查文件,如果文件不存在则创建
private void ExistsFile(string FilePath)
{
if(!File.Exists(FilePath))
File.Create(FilePath);
}
private void Button2_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//读取文件
StreamReader sr = new StreamReader(MapPath("weather.txt"), System.Text.Encoding.Default);
string input = sr.ReadToEnd();
sr.Close();
input = input.Replace("\r\n", "<br>").Replace("\n", "<br>");
this.TextBox1.Text = input;
}
private void Button1_Click(object sender, System.EventArgs e)
{
ExistsFile(MapPath("weather.txt"));//检查文件是否存在
//写入文件
StreamWriter sr = new StreamWriter(MapPath("weather.txt"),false,System.Text.Encoding.Default);
sr.Write(this.TextBox1.Text);
sr.Close();
}


浙公网安备 33010602011771号