English 中文(简体)
哪一种书写方法可以使用?
原标题:Which writing to file method to use?
  • 时间:2011-07-08 16:30:36
  •  标签:
  • c#

I m really getting confused by how many different ways there is to write data to a file just with System.IO.
I mean, between FileStream, StreamWriter or just the System.IO.file methods... Which one is the best to use?

如果你看到你能够使用与其中任何一种不同的构造,如使用<条码>(<>>使用<>条码/代码>,它就更加令人困惑。

他们之间是否有任何区别? 在线辅导似乎只贴在其中一带,完全忽视其他辅导。 其中一些辅导员甚至使用不同的参考资料,在(在某些情况下使用<条码>File类型,在另一些情况下使用<条码>FileInfo 类型,甚至只是为其行程/名称打脚。

Any of them is more efficient than the other?

最佳回答

Stream is an summaryion for “bytes of data” that work with what other than file, as bytes sent over a web.

<>TextReader和TextWriters系指与text合作。 简化

<代码>File类别特别旨在将档案作为unit 实体处理,而不是作为长期 by处理。 因此:

  • If the file could be big (I d say that means 1 MiB+), use the Stream-related classes. It usually makes no sense to keep a 10-MiB byte[] or string in memory, unless you really need random access to all of it.
  • If it s always small (so that it makes sense to keep it all in memory), you can just use the File class to read and write byte[]s or strings.
问题回答

有许多办法,因为有许多办法可以安排数据发送。 你们有多阵s吗? 您是否从其他一些来源(如网络流)收集数据? 你们是否想像一个记录那样写文字?

这将有助于了解你想要写什么,然后我们能够帮助你决定如何写字。

Oh,并且始终如一地利用你。 即便贵国的法典失败了,你也获得资源清理。

<代码>StreamWriter和StreamReader各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各式各样。

这取决于你们需要哪些程度的抽象工作,以及你与哪一类数据(文本与本通)。

如果你只需要将数据输入档案,则你可以使用双轨制(只用<条码>/条码>)和<条码>(除另有规定外,使用<条码>/条码>的助手法。

www.un.org/spanish/ga/president

如果你需要写字,而且你想要进行低水平控制,例如规定档案方式、系统权利、档案共享和其他此类选择,那么,你需要与档案库合作。 您也可通过将案文通过至<代码>StreamWriter或将案文作为特例处理(例如,通过使用<代码>Encoding)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签