net导入txt文件|用NET怎么把一条数据插入TXT文件中

Ⅰ VB.NET中怎么导入TXT文本里的数据

比如说用Richtext控件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim file As String = "f:/x.txt" RichTextBox1.LoadFile(file) MsgBox("ok") End Sub

Ⅱ 用.NET怎么把一条数据插入TXT文件中

string str = "把我写入a.txt中"; File.AppendAllText("D:\\a.txt", str);

Ⅲ Asp.net怎样将一个数据写入到.txt文本文件

using(FileStream fs = new FileStream (文件地址,FileMode.Create)){byte[] bytefile = Enconding.UTF8. Getbytes(文件地址);fs.Write(bytefile,0,bytefile.Leangth);}这样就可以了,不过会覆回盖之前的记答录

Ⅳ 如何将已有的txt格式的文件数据导入VB.NET程序中,(也就是在VB.NET中读取所需的txt文

一个按钮,一个文本框,把文本框设置成多行显示。代码如下:Imports System.IOPublic Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim r As New StreamReader(Application.StartupPath & "\ABC.txt", System.Text.Encoding.Default) '用StreamReader打开文本文件 Dim s As String TextBox1.Text = "" Do While r.Peek > -1 '是否到文件尾 s = r.ReadLine '从打开的文件中读取一行内容 TextBox1.Text = TextBox1.Text & s & vbCrLf '添加到文本框TextBox1.Text的后面并回车 Loop r.Close() '关闭对象 End SubEnd Class

Ⅳ VB.NET怎样实现导入导出文本文件

用System.IO.StreamReader类可以读各类文本文件,用System.IO.StreamWriter 类则可以写各类文本文件,从而实现导入导出文本文件功能。这两个类均支持各类编码格式(默认的是Unicode和UTF-8)。

Ⅵ asp.net 怎么把txt文本内容导入sql表里

streamreader sr=new streamreader("d:\\a.txt");//这里假设是一行一个数据while(true)//这里sr有个方法可以判断是否读取到了结尾,我忘记是哪个回了,你可以自己找下,答替换掉true{string str=dr.readline();//执行插入数据库……}sr.close();

Ⅶ vb.net 中对txt文件的读取、写入的方法!始终保持txt里面只有一行!

Public Class Form1 Private Sub 写入文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 写入文件.Click FileOpen(1, "D:\一行文件.txt", OpenMode.Output) ' Open file for output. WriteLine(1, "想只保留文件为一行 那你就写一行好了") ' Print blank line to file. FileClose(1) ' Close file. End Sub Private Sub 读取文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 读取文件.Click Dim TextLine As String FileOpen(1, "D:\一行文件.txt", OpenMode.Input) ' Open file for output. TextLine = LineInput(1) '读取一行就了 MsgBox(TextLine) FileClose(1) End SubEnd Class最简单的方法 还有很多方法 自己研究吧亲 希望能帮到你

Ⅷ 在使用ENDNOTE的NEtoEN时,导入TXT文件信息时为什么不成功啊

我也碰到过导入出现乱码的问题。网络后得到了答案,与你分享下:用EndNote导入时,要根据文件的编码来选择TextTranslation。 文件编码的确定方法为:用记事本打开要导入的文件,然后选择“文件”->“另存为”,看一下弹出的保存文件对话框最下面的“编码”,一般会出现Unicode和ANSI两种。 如果是Unicode的话,用EndNote导入时的TextTranslation 要用Unicode(UTF-8),如果时ANSI,用No Translation就可以了。 在用NoteExpress导入题录时可以让软件自动识别,而不用自己去判断了。 PS 在用NoteExpress导出时,右上角有一处,选择UTF-8;导入至Endnote时,TextTranslation 也要用Unicode(UTF-8)。

Ⅸ .NET实现(把文本文件中的数据导入到数据库)报错提示:无法从已关闭的 TextReader 中读取。

///<summary>///创建并获取目录,主要用于用户文件上传的目录,目录创建在resources/upload下///</summary>///<paramname="customize">自定义类别可以是空NULL,此参数不为空时在upload下会再新建一层目录,如:adminPic则返回../resources/upload/adminPic/年/月/</param>///<returns>../resources/upload/adminPic/年/月/</returns>(stringcustomize){stringpath=HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath+"/resources/upload/"+((customize==string.Empty)?(customize.ToString()+"/"):(""))+DateTime.Now.Year+"/"+DateTime.Now.Month+"/");try{if(!File.Exists(path)){Directory.CreateDirectory(path);}returnpath;}catch(Exception){returnHttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["errorPath"]).ToString();}}///<summary>///文本数据导入///</summary>///<paramname="sender"></param>///<paramname="e"></param>protectedvoidBut_importChinaBank_Click(objectsender,EventArgse){if(flChinaBank.PostedFile.FileName==""){Page.ClientScript.RegisterStartupScript(this.GetType(),"1","<script>alert('导入的文本文件不存在!');</script>");}else{stringFilePath=getAndCreatePath("");stringFileName=DateTime.Now.Ticks.ToString();//stringtableName;stringpostFileName;//后缀名stringnewName;try{intpos=flChinaBank.PostedFile.FileName.LastIndexOf(".")+1;postFileName=flChinaBank.PostedFile.FileName.Substring(pos,flChinaBank.PostedFile.FileName.Length-pos);//后缀名newName=FilePath+FileName+"."+postFileName;flChinaBank.PostedFile.SaveAs(newName);}catch(Exceptionexec){throw(exec);}FileStreamfs=newFileStream(newName,FileMode.Open,FileAccess.Read);StreamReaderm_streamReader=newStreamReader(fs);m_streamReader.BaseStream.Seek(0,SeekOrigin.Begin);stringvalue=m_streamReader.ReadLine();string[]stringSeparators=newstring[]{""};stringsql="";intnonquery=0;for(inti=0;value!=null;i++){//value=value.Replace(",","");string[]array=value.Split(stringSeparators,StringSplitOptions.RemoveEmptyEntries);sql+=string.Format("insertintoL_POSImportInfo_Sharevalues('{0}','{1}','{2}','{3}','{4}','{5}',{6},{7},{8},'{9}','{10}','{11}','{12}','{13}','{14}','{15}');",0,104370157225027,array[0].ToString(),(array[3].Substring(4,4)+array[4]).ToString(),array[2],"无",double.Parse(array[5].Replace(",","").ToString())*100.00,double.Parse(array[6].ToString())*100.00,double.Parse(array[7].ToString())*100.00,"无",double.Parse(array[8].ToString())*100.00,"无","无","",0,DateTime.Now.ToString("s"));}nonquery=baser.ExecuteSQL(sql);if(nonquery>0){Page.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),"<script>alert('导入成功');</script>");GridView1.EditIndex=-1;dataDind(0);}else{Page.ClientScript.RegisterStartupScript(this.GetType(),Guid.NewGuid().ToString(),"<script>alert('导入失败!');</script>");}m_streamReader.Close();fs.Close();//删除上传的文件if(File.Exists(newName)){File.Delete(newName);}}}}

Ⅹ 在.NET中怎么读取.txt文件

class Program { static void Main(string[] args) { //使用StreamReader来读取一个文本文件 //using (StreamReader sr = new StreamReader(@"C:\Users\SpringRain\Desktop\抽象类特点.txt",Encoding.Default)) //{ // while (!sr.EndOfStream) // { // Console.WriteLine(sr.ReadLine()); // } //}//使用StreamWriter来写入一个文本文件 using (StreamWriter sw = new StreamWriter(@"C:\Users\SpringRain\Desktop\newnew.txt",true)) { sw.Write("看我有木有把你覆盖掉"); } Console.WriteLine("OK"); Console.ReadKey(); } }


赞 (0)