写了个烂代码,请原谅

None.gif using  System.Text ;
None.gif
using  System.IO ;
ExpandedBlockStart.gifContractedBlock.gif
/**/ /// <summary>
InBlock.gif
/// Summary description for file
ExpandedBlockEnd.gif
/// </summary>

None.gif public   class  file
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
private string _filename;
InBlock.gif    
private StreamReader ts;
InBlock.gif    
private StreamWriter ws;
InBlock.gif    
public bool opened,openforwriter,creatfile;
InBlock.gif    
private string _filepath=Directory .GetCurrentDirectory () ;
InBlock.gif    
InBlock.gif
InBlock.gif    
public file()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        Init();
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public file(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{   Init();
InBlock.gif
InBlock.gif    _filename 
= filename;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*初始化*/
InBlock.gif    
private void Init()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{ opened = false;
InBlock.gif    openforwriter 
= false;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*读取文件*/
InBlock.gif    
public bool OpenForRead(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{ _filename = filename;
InBlock.gif    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        ts 
= new StreamReader(_filename);
InBlock.gif        opened 
= true;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
catch (FileNotFoundException ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn false; }
ExpandedSubBlockEnd.gif}

InBlock.gif    
public bool OpenForRead()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn OpenForRead(_filename); 
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public string ReadLine()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn ts.ReadLine(); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*写文件*/
InBlock.gif    
InBlock.gif    
public bool OpenForWrite()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn OpenForWrite(_filename); }
InBlock.gif    
public bool OpenForWrite(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        _filename 
= filename;
InBlock.gif        
try
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ws 
= new StreamWriter(_filename);
InBlock.gif            openforwriter 
= true;
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
catch (FileNotFoundException ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gifreturn false; }
          

InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public void WriteLine(string cha)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{ ws.WriteLine(cha); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public string FilePath dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
get dot.gifreturn _filepath; }
ExpandedSubBlockStart.gifContractedSubBlock.gif        
set dot.gif{ _filepath = value; }
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*创建文件*/
InBlock.gif    
public bool CreatFile()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn CreatFile(_filename); }
InBlock.gif    
public  bool CreatFile(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{ _filename = filename;
InBlock.gif    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (File.Exists(_filepath + _filename))
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{ File.Delete(_filename);
InBlock.gif        File.Create(_filepath 
+ _filename);
ExpandedSubBlockEnd.gif        
return  true ;}

InBlock.gif         
ExpandedSubBlockEnd.gif      }

InBlock.gif        
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{return false ;}
InBlock.gif    
ExpandedSubBlockEnd.gif}

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*删除文件*/
InBlock.gif    
public bool DeleteFile()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gifreturn DeleteFile(_filename); }
InBlock.gif    
public bool DeleteFile(string filename)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{ _filename =filename ;
InBlock.gif    
if (File.Exists(_filepath + _filename))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        File.Delete(filepath 
+ _filename);
InBlock.gif        
return true;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
else dot.gifreturn false; }
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
写一些垃圾代码,有时间利用多态重写代码
不好意思

转载于:https://www.cnblogs.com/kttt/archive/2006/09/25/514689.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值