从位置读取文件
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”?
FileStream infile = new FileStream(@"C:\Users\John\Desktop\ProjectNew\nov.txt", FileMode.Open, FileAccess.Read);
int position = x.Length;
infile.Seek(position, SeekOrigin.Begin);
But Seek method returns number. How to read the file 'infile' from position to end in a string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是你所追求的吗?假设您想从位置 100 开始阅读......
Is this what you're after? Assuming you wanted to start reading from position 100...
Seek 方法应该返回一个数字,流中的新位置。现在只需调用您想要的任何 Read 函数即可。
The Seek method is supposed to return a number, the new position in the stream. Now just call whatever Read function you want.
Seek() 只将文件指针放置在其他地方。如果您在查找之前进行读取,它将从文件的开头读取。如果您在查找后读取,它将从位置开始读取。
因此,要从该位置读取文件到末尾,请执行
Seek()
,然后执行Read()
或ReadToEnd()
。Seek() only places the file pointer somewhere else. If you do a read before the seek, it will read from the beginning of the file. If you read after the seek, it will start reading from position.
So to read the file from position to the end, do
Seek()
, followed byRead()
orReadToEnd()
.