如何使用c#..写入特定位置的空文件? [英] How to write into a empty file in a perticular position using c#..?

查看:64
本文介绍了如何使用c#..写入特定位置的空文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have tried to write into a file..now i am able to write but not able to write into perticular position in a file







我尝试了什么:



i试图写到文件..现在我能够写但不能写入文件中的特定位置




What I have tried:

i have tried to write into a file..now i am able to write but not able to write into perticular position in a file

推荐答案

你正在寻找Stream。寻求(..) [ ^ ] - 用于将虚拟光标放置在流中的方法(可能是FIL e)。



请注意,写一个流的中间不会插入你正在编写的内容,但会覆盖该位置的任何内容。没有简单的开关来改变它;如果你想插入,你必须通过阅读和重写来向后移动其余部分。



取决于你是哪个特定班级对于文件访问,你可能会发现Seek-method不是直接在该类对象上,而是在BaseStream属性下,例如: myStreamWriter.BaseStream.Seek(..)



还要注意,通常不允许通过您通常可以使用的文件获取搜索功能。您可以检查流是否允许使用其属性 .CanSeek 进行搜索。
You're looking for the Stream.Seek(..)[^]-method with which you can position your "virtual cursor" in a stream (which may be a file).

Be aware that writing "in the middle" of a stream will not insert whatever you're writing but it will overwrite whatever already is at that position. There's no simple switch to change this; if you'd want to insert, you'd have to move the remainder backwards yourself by reading and re-writing it.

Depending on which particular class you're using for file-access you might find the Seek-method not directly on that class-object but under the BaseStream-property, e.g.: myStreamWriter.BaseStream.Seek(..) .

Also be aware that the ability to seek is not generally allowed for a stream, with files you'll usually be able to though. You can check whether a stream allows seeking with its property .CanSeek .


这篇关于如何使用c#..写入特定位置的空文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆