简单文件读写
来源:互联网 发布:java输出当前系统时间 编辑:程序博客网 时间:2024/05/18 01:16
using System;
using System.IO;
using System.Text;
namespace ReadTxt
{
/// <summary>
///简单的文件读写
/// </summary>
class Class1
{
/// <summary>
/// Entry Point
/// </summary>
[STAThread]
static void
{
string path = Directory.GetCurrentDirectory() + "//Result//";
string date = DateTime.Now.ToLongDateString();
path += date + ".txt";
SafeWrite( path, "liujuejue" );
Console.WriteLine( SafeRead( path ) );
Console.ReadLine();
}
public static string SafeRead( string path )
{
StreamReader tr = File.OpenText( path );
string temp = string.Empty;
string s = tr.ReadLine();
while( s != null )
{
temp += s;
s = tr.ReadLine();
}
tr.Close();
return temp;
}
public static void SafeWrite( string path, string content )
{
FileStream fs = null;
if( !File.Exists( path ) )
{
fs = File.Create( path );
}
else
{
fs = File.OpenWrite( path );
}
StreamWriter sw = new StreamWriter( fs );
sw.BaseStream.Position = fs.Length;
sw.WriteLine( content );
sw.Flush();
sw.Close();
fs.Close();
}
}
}
- 简单文件读写
- php简单读写文件
- 简单的文件读写
- perl简单读写文件
- C++ 简单文件读写
- C#简单读写文件
- 简单的读写文件
- 简单的读写文件
- Java简单文件读写
- 文件的简单读写
- 简单的文件读写
- 文件的简单读写
- ini文件简单读写
- 简单的文件读写
- Java简单文件读写
- csv文件简单读写
- c++ 文件读写简单示例
- Ruby简单的读写文件
- 探索软件设计模式(一)
- 简单谈基于SQL SERVER 分页存储过程的演进
- asp.net(C#)中进制之间相互转化
- 条件表达式的语法
- 探索软件设计模式(二)
- 简单文件读写
- SAP相关的网址收集
- 关于统计考勤记录的一段SQL
- blob存储文件示例程序
- AXIS学习笔记
- 读写INI文件
- 系统设计的一些原则(转)
- 如何限制程序只运行一次
- 发现一枚牛人