当前位置: 移动技术网 > IT编程>开发语言>.net > 读取txt文件内容,并按一定长度分页显示

读取txt文件内容,并按一定长度分页显示

2019年05月14日  | 移动技术网IT编程  | 我要评论

toshi近亲,赵燕国彰的老婆,亡国的阿基德

private list<string> savecontentupload(fileupload file)
{
list<string> list_content = new list<string>();//定义集合,存储文件内容
double count = 0;
int pagesize = 1000;//设置每次读取的长度为1000
string context = "";//上传文件内容
using (stream reader = file.postedfile.inputstream)
{
int filelen = file.postedfile.contentlength;//获取上传文件的大小
byte[] buff = new byte[filelen];
reader.read(buff, 0, filelen);
reader.position = 0;
system.io.streamreader sr = new system.io.streamreader(reader, system.text.encoding.default);
context = sr.readtoend();
count = context.length;
int num = convert.toint32(math.ceiling(count / pagesize));
for (int i = 0; i < num; i++)
{
int sum = pagesize;
if (count - (i * pagesize) < pagesize)
{
sum = convert.toint32(count - (i * pagesize));
}
string text = context.substring(i * pagesize, sum);
list_content.add(text);
}
}
return list_content;
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网