|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
数据挖掘有点高深的,主要估计就是使用一些算法提取一些实用的数据。学好数据挖掘的话可以应聘baidu或者google,但是一般人家对算法的要求听高的。你最好还是学点应用型的吧。这种主要是研究型的。Introduction
Readingandwritingtextfilesmaysometimesbequitehandyinprogramming.Youmightwanttomaintainyourowntext-styleconfigurationfiles.Oreditautoexec.batfromyourprogram.In.NetwehaveanabstractclasscalledaStreamclasswhichprovidesmethodstoreadandwritefromastore.TheFileStreamclassisaStreamclassderivedclasswhichwrapsthestreamingfunctionalityaroundafile.InthisarticleIlldemonstratehowyoucanusethisclassalongwithseveralreaderandwriterclassestoreadfromafile,writetoafile,createafileandevenretrieveinformationaboutafile.Ihaveprovidedacommentedprogrambelow.
TheProgram
usingSystem;
usingSystem.IO;
publicclassnishfiles
{
publicstaticvoidMain(String[]args)
{
//Createafilenish.txtinthecurrentdirectory
FileStreamfs=newFileStream("nish.txt",FileMode.Create,FileAccess.ReadWrite);
//NowletsputsometextintothefileusingtheStreamWriter
StreamWritersw=newStreamWriter(fs);
sw.WriteLine("Heynow!Heynow!
Iko,Iko,unday");
sw.WriteLine("Jockamofeenoainanay?
Jockamofeenanay?");
sw.Flush();
//WecanreadthefilenowusingStreamReader
StreamReadersr=newStreamReader(fs);
sr.BaseStream.Seek(0,SeekOrigin.Begin);
strings1;
Console.WriteLine("abouttoreadfileusingStreamReader.ReadLine()");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
while((s1=sr.ReadLine())!=null)
Console.WriteLine(s1);
Console.WriteLine();
//WecanreadthefilenowusingBinaryReader
BinaryReaderbr=newBinaryReader(fs);
br.BaseStream.Seek(0,SeekOrigin.Begin);
Byteb1;
Console.WriteLine("abouttoreadfileusingBinaryReader.ReadByte()");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
while(br.PeekChar()>-1)
{
b1=br.ReadByte();
Console.Write("{0}",b1.ToChar());
if(b1!=13&&b1!=10)
Console.Write(".");
}
br.Close();
Console.WriteLine();
sw.Close();
sr.Close();
fs.Close();
//UsetheFileclasstogetsomeinfoonourfile
Console.WriteLine("PrintsomeinfoonourfileusingtheFileclass");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
Filef=newFile("nish.txt");
Console.WriteLine("Filename:{0}",f.Name);
Console.WriteLine("Filenameinfull:{0}",f.FullName);
Console.WriteLine("Filesizeinbytes:{0}",f.Length);
Console.WriteLine("Filecreationtime:{0}",f.CreationTime);
}
}
TheOutputandexplanation
ThiswastheoutputIgotonmymachine.
F:c#files>files1
abouttoreadfileusingStreamReader.ReadLine()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Heynow!Heynow!
Iko,Iko,unday
Jockamofeenoainanay?
Jockamofeenanay?
abouttoreadfileusingBinaryReader.ReadByte()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
H.e.y..n.o.w.!..H.e.y..n.o.w.!.
I.k.o.,..I.k.o.,..u.n.d.a.y.
J.o.c.k.a.m.o..f.e.e.n.o..a.i..n.a.n..a.y.?.
J.o.c.k.a.m.o..f.e.e..n.a.n..a.y.?.
PrintsomeinfoonourfileusingtheFileclass
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Filename:nish.txt
Filenameinfull:F:c#files
ish.txt
Filesizeinbytes:83
Filecreationtime:10/13/012:18PM
F:c#files>
不可能天天有学习.net),我一同学说,你应该早就有作品啦。我惶惶然…… |
|