打开文本文件并逐行读取 [英] open text file and read it line by line

查看:67
本文介绍了打开文本文件并逐行读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试打开一个文本文件并逐行阅读。但是我正在考虑这个例外,请建议我。

异常详情:

System.UnauthorizedAccessException被捕获

消息=访问路径' C:\ Users \ karthick.k \Desktop \ OB8182301_20130823_020658.txt'被拒绝。

来源= mscorlib

StackTrace:

在System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)

at System.IO.FileStream.Init(String path,FileMode mode,FileAccess access,Int32 rights,Boolean useRights,FileShare share ,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,String msgPath,Boolean bFromProxy)

在System.IO.FileStream..ctor(字符串路径,FileMode模式,FileAccess访问,FileShare共享)
System.IO.File.OpenRead(字符串路径)

StorageBase.SbWebPages.Korta的
PaymentImport.paymentKorta()在F:\ GeymslurAlpha \ StorageBase \SbWebPages \ KortaPaymentImport.aspx.cs:第214行

InnerException:



谢谢大家。

Hi all,

I am trying to open a text file and reading it line by line.But I am geting this exception please suggest me.
exception details:
System.UnauthorizedAccessException was caught
Message=Access to the path 'C:\Users\karthick.k\Desktop\OB8182301_20130823_020658.txt' is denied.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.OpenRead(String path)
at StorageBase.SbWebPages.KortaPaymentImport.paymentKorta() in F:\GeymslurAlpha\StorageBase\SbWebPages\KortaPaymentImport.aspx.cs:line 214
InnerException:

Thank you all.

推荐答案

尝试更改文本文件位置驱动器除了c:
Try to change text file Location drive Except c:


它抱怨文件因为运行应用程序的用户无法访问路径的某些部分。这很可能是因为你试图通过网站服务器上的固定地址访问文件。



这里有几件事,但不是明确你应该做些什么来解决它:如果文件在服务器上,那么你不应该试图通过用户路径访问它,因为绝对不能保证你的用户甚至存在于网络服务器上,并且几乎有无论如何,网站都无法在该用户下运行。

该文件也有可能在客户端上 - 在这种情况下,您的代码根本无法访问它,除非它已被上传到首先是服务器,在这种情况下你应该保存在相对于网站的路径中。



我不能在这里提出具体的建议,因为我看不到你的代码!
It's complaining about the file because some part of the path is not accessible to the user that is running the application. Most likely this is because you are trying to access a file via a fixed address on the server of your website.

There are a couple of things here, but it's not obvious what you should do to fix it: if the file is on the server, then you should not be trying to access it via a user path, because there is absolutely no guarantee that your user even exists on a webserver, and there is almost no chance that a website will run under that user anyway.
There is also the chance that the file is on the client - in which case your code cannot access it at all unless it had been uploaded to the server first, in which case you should be saving if in a path relative to the website anyway.

I cannot make concrete suggestions here, because I can't see your code!


访问这里......



http://www.csharp411.com/c-read-text-file-line-by-l ine / [ ^ ]







http://www.homeandlearn.co.uk/csharp/csharp_s11p2.html [ ^ ]
visit Here...

http://www.csharp411.com/c-read-text-file-line-by-line/[^]

or

http://www.homeandlearn.co.uk/csharp/csharp_s11p2.html[^]


这篇关于打开文本文件并逐行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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