C# 读取非txt文件
我正在尝试读取 *.jsp 文件的内容并需要检索特定的字符串。
我在 C# 中尝试了许多文件处理方法,但似乎都只适用于 txt 文件。是否可以对具有不同扩展名的文件使用相同的方法?
I am trying to read the contents of a *.jsp file and need to retrieve a specific string.
I tried many file handling methods in C# but it seems all work only with txt files. Is it possible to use the same methods for a file with a different extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET 中的普通 IO 类不依赖于文件扩展名。您应该能够使用:
... 假设 JSP 采用 UTF-8 编码。您应该找出文件的编码并使用该编码加载它。如果这就是您遇到的问题,我不会感到惊讶,尽管您没有指定任何内容。
The normal IO classes in .NET don't depend on the file extension. You should be able to use:
... assuming the JSP is encoded in UTF-8. You should find out the encoding of the file and load it using that encoding. I wouldn't be surprised if that turned out to be the problem you were having, although you haven't specified anything.