从位置读取文件 [英] Read file from position
本文介绍了从位置读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FileStream infile = new FileStream(@"C:\Users\John\Desktop\ProjectNew\nov.txt", FileMode.Open, FileAccess.Read);
int position = x.Length;
infile.Seek(position, SeekOrigin.Begin);
但Seek方法返回数字。如何从字符串中读取infile文件?
But Seek method returns number. How to read the file 'infile' from position to end in a string?
推荐答案
假设你想从位置100开始阅读...使用(FileStream fs = new FileStream(@file.txt)来使用
Is this what you're after? Assuming you wanted to start reading from position 100...
using (FileStream fs = new FileStream(@"file.txt", FileMode.Open, FileAccess.Read))
{
fs.Seek(100, SeekOrigin.Begin);
byte[] b = new byte[fs.Length - 100];
fs.Read(b, 0, (int)(fs.Length - 100));
string s = System.Text.Encoding.UTF8.GetString(b);
}
这篇关于从位置读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文