constant con = new constant();

private void loadlistbox2()
{
dataGridView1.ColumnCount = 1;
string z;
if (File.Exists(".//allitems.txt"))
{
FileStream fs = new FileStream(".//allitems.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);

StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("utf-8"));
try
{
while (true)
{
z = sr.ReadLine();
if (z == null) break;
dataGridView1.Rows.Add(z);
}
}
finally
{
sr.Close();
fs.Dispose();
fs.Close();
}
}
}
string st = "";

private void savetestitem()
{
// dataGridView1.ColumnCount = 1;
if (File.Exists(".//allitems.txt"))
{
FileStream fs = new FileStream(".//allitems.txt", System.IO.FileMode.Open, System.IO.FileAccess.Write);

StreamWriter sr = new StreamWriter(fs, System.Text.Encoding.GetEncoding("utf-8"));
try
{
for (int i = 0; i < 22; i++)
{
for (int j = 0; j < 1; j++)
{
st = st + dataGridView1.Rows[i].Cells[j].Value;
}
sr.WriteLine(st);
st = "";

//for (int i = 0; i < dataGridView1.Rows.Count; i++)
//{
// sr.WriteLine(dataGridView1.Rows[i].Cells);
// }
}

}
finally
{
sr.Close();
fs.Dispose();
fs.Close();
}
}
}

dataGridView读写文本的更多相关文章

  1. 背水一战 Windows 10 (89) - 文件系统: 读写文本数据, 读写二进制数据, 读写流数据

    [源码下载] 背水一战 Windows 10 (89) - 文件系统: 读写文本数据, 读写二进制数据, 读写流数据 作者:webabcd 介绍背水一战 Windows 10 之 文件系统 读写文本数 ...

  2. iOS 9应用开发教程之多行读写文本ios9文本视图

    iOS 9应用开发教程之多行读写文本ios9文本视图 多行读写文本——ios9文本视图 文本视图也是输入控件,与文本框不同的是,文本视图可以让用户输入多行,如图2.23所示.在此图中字符串“说点什么吧 ...

  3. python_py2和py3读写文本区别

    python2和python3的区别? python 2  str             对应      python3 bytes python 2 uincode            对应   ...

  4. 零基础学python-3.7 还有一个程序 python读写文本

    今天我们引入另外一个程序,文件的读写 我们先把简单的程序代码贴上.然后通过我们多次的改进.希望最后可以变成一个简单的文本编辑器 以下是我们最简单的代码: 'crudfile--读写文件' def re ...

  5. Python之读写文本数据

    知识点不多 一:普通操作  # rt 模式的 open() 函数读取文本文件 # wt 模式的 open() 函数清除覆盖掉原文件,write新文件 # at 模式的 open() 函数添加write ...

  6. Python-py2和py3读写文本区别

    python2和python3的区别? python 2  str             对应      python3 bytes python 2 uincode            对应   ...

  7. delphi 读写文本

    将字符串写入txt文档,读取txt文档中的内容. //一次写字符串到文本文件,每次都会将原来的内容替换掉. procedure FilePutContents(f,s:String); // f为文件 ...

  8. C#读写文本和连接数据库

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. 读写文本(.txt)文件 .NET

    http://www.cnblogs.com/jx270/archive/2013/04/14/3020456.html (一) 读取文件 如果你要读取的文件内容不是很多,可以使用 File.Read ...

随机推荐

  1. mysql左连接查询结果不准确

    现有四张表 表(1)res_resource_catalog 表(2)res_catalog_classify 表(3)res_resource_classify 表(4)res_resource_m ...

  2. NIO网络访问模式实践

    1.创建NioNest12类 一个线程监听5个端口的事件 public class NioTest12 { public static void main(String[] args) throws ...

  3. shell 备份mysql

    shell脚本备份mysql,放在crontab中,可以作为每日测试用数据库备份 #!/bin/bash string_time=`date +%Y%m%d%H%M`; file_path=`date ...

  4. sigmoid与softmax 二分类、多分类的使用

    二分类下,sigmoid.softmax两者的数学公式是等价的,理论上应该是一样的,但实际使用的时候还是sigmoid好 https://www.zhihu.com/question/29524708 ...

  5. PHP打印日志类

    PHP简单封装个打印日志类,方便查看日志: <?php /** * Created by PhpStorm. * User: zenkilan * Date: 2019/9/26 * Time: ...

  6. linux 结束某个进程,并且结束子进程

    pid=49184 childid=`ps -ef|grep $pid|grep -v grep|awk '{printf " %s",$2 }'` kill -9 $childi ...

  7. java Random 带权重的随机选择

    实际场景中,经常要从多个选项中随机选择一个,不过,不同选项经常有不同的权重. /** * Created by xc on 2019/11/23 * 带权重的随机选择 */ public class ...

  8. 分布式ID生成总结

    1.数据库自增id 新建一个公共库,库里面新建一个序列表,主键id自增,每次请求增加数据都往这个表中插入数据,然后获取到id,然后使用即可. 优点:方便简单 缺点:单库生成自增id,高并发下,会有瓶颈 ...

  9. 在Eclipse中设置中文JavaDOC

    参考: 在Eclipse中设置中文JavaDOC

  10. CentOS升级kernel

    CentOS升级kernel 升级命令: yum update kernel yum update kernel-devel yum update kernel-firmware yum update ...