文件I / O. [英] file I/O

查看:47
本文介绍了文件I / O.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了处理超过100 MB的大文件,dotnet中是否有办法通过缓冲区打开文件的某些字节?


它如果打开并拆分整个文件,则会很不稳定。取而代之的是打开文件的一小部分或者任何其他选择。

解决方案

我不是认为打开1M文件或100M文件之间有任何不同

如果你使用流。 Streams是使用缓冲区设计的,只会在您想要的信息中读取
。所以,你可以使用

FileStream打开你的文件并寻找到指定的位置,然后读取你想要的
想要的字节数。


现在,如果你需要更复杂的处理,例如获取由换行符分隔的某些

文件的第200行,那么你可能需要这样的东西。处理你自己或依赖像Stream阅读器这样的东西。

" shiva" < SH *** @ discussions.microsoft.com>在消息中写道

新闻:C7 ********************************** @ microsof t.com ...

为了处理超过100 MB的大文件,dotnet中有没有办法通过缓冲区打开文件的某些字节?

如果打开并拆分整个文件,那就太不稳定了。相反,在打开文件的小块时会有一种方法或任何替代方法。



感谢您的反馈。好吧,我只是想打印一个30MB的文件

和它摇摇欲坠。当我们运气好的时候,它有时会被打印,有时候好像它会起作用。\\ b
以下

代码除非或其他方面有问题。还有很多交易要做,而不仅仅是打印,但是在打印时它就是在这里偷偷摸摸。


Private Sub Button1_Click(ByVal sender As Object,ByVal e as

System.EventArgs)处理Button1.Click

''打开文件阅读

Dim FILENAME As String

Dim FileContents As String

Dim iCount As Integer

iCount = 1


FILENAME =" c:\ \ Filereader \\File1.txt"


尝试


''获取可用于读取文件的StreamReader类

Dim objStreamReader As StreamReader

objStreamReader = File.OpenText(FILENAME)


''逐行读取

虽然真实

FileContents = CType(objStreamReader.ReadLine,String)

如果不是FileContents = Nothing那么

Response.Write( iCount&Begin Line1&"< br>")

Response.Write(FileC ontents)

Response.Write("< br>" &安培; iCount& 结束行1 &安培; "< br>")

iCount = iCount + 1

''lblRawOutput.Text& = FileContents& vbCrLf

否则:退出时

结束如果

结束时


''设置文本该文件的Web控件

''lblRawOutput.Text =内容


objStreamReader.Close()


Catch ex As Exception

Response.Write(ex.Message)

结束尝试


结束子


" Peter Rilling"写道:

我不认为打开1M文件或100M文件之间有任何不同
如果您使用流。 Streams设计有缓冲区,只能读取您想要的信息。因此,您可以使用
FileStream打开文件并寻找指定位置,然后读取您想要的字节数。

现在,如果您需要更复杂的处理,如获得由换行符分隔的某些
文件的第200行,那么您可能需要自己处理或依赖于像Stream读取器之类的东西。

" ;希瓦" < SH *** @ discussions.microsoft.com>在消息中写道
新闻:C7 ********************************** @ microsof t.com。 ..

为了处理超过100 MB的大文件,dotnet中有没有办法通过缓冲区打开文件的某些字节?




谢谢你反馈先生。好吧,我只是想打印一个30MB的文件

和它摇摇欲坠。当我们运气好的时候,它有时会被打印,有时候好像它会起作用。\\ b
以下

代码除非或其他方面有问题。还有很多交易要做,而不仅仅是打印,但是在打印时它就是在这里偷偷摸摸的。

展开 | 选择 | Wrap | 行号

Inorder to handle large files over 100 MB, is there a way in dotnet to open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.

解决方案

I don''t think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...

Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.



Thank you for the feedback Sir. Well, i am just trying to print a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as if it works
when we have luck. Unless or otherwise something is wrong with the following
code. There is lot more transactions to do than just printing, but it is
skaky right here when printing.

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
''Open a file for reading
Dim FILENAME As String
Dim FileContents As String
Dim iCount As Integer
iCount = 1

FILENAME = "c:\\Filereader\\File1.txt"

Try

''Get a StreamReader class that can be used to read the file
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FILENAME)

''Read Line By Line
While True
FileContents = CType(objStreamReader.ReadLine, String)
If Not FileContents = Nothing Then
Response.Write(iCount & "Begin Line1" & "<br>")
Response.Write(FileContents)
Response.Write("<br>" & iCount & "End Line1" & "<br>")
iCount = iCount + 1
''lblRawOutput.Text &= FileContents & vbCrLf
Else : Exit While
End If
End While

''Set the text of the file to a Web control
''lblRawOutput.Text = contents

objStreamReader.Close()

Catch ex As Exception
Response.Write(ex.Message)
End Try

End Sub

"Peter Rilling" wrote:

I don''t think there is any different between opening a 1M file or 100M file
if you use a stream. Streams are designed with buffers and will only read
in as much information as you want. So, you could open your file using
FileStream and seek to a specified location, then read as many bytes as you
want.

Now, if you need more complex processing like getting the 200th row of some
file that are delimited by newlines, then that is something that you might
have to process yourself or rely on something like a Stream reader.
"shiva" <sh***@discussions.microsoft.com> wrote in message
news:C7**********************************@microsof t.com...

Inorder to handle large files over 100 MB, is there a way in dotnet to
open
only certain bytes of the file by buffer ?

It is shaky if the entire file is opened and splitted. Instead is there a
way or any alternatives on opening small chunk of the file.




Thank you for the feedback Sir. Well, i am just trying to print a 30MB file
and its shaky. It gets hogged sometimes amd prints sometimes as if it works
when we have luck. Unless or otherwise something is wrong with the following
code. There is lot more transactions to do than just printing, but it is
skaky right here when printing.

Expand|Select|Wrap|Line Numbers


这篇关于文件I / O.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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