FileSystemObject的 - 读的Uni code文件 [英] FileSystemObject - Reading Unicode Files

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

问题描述

经典ASP,VBScript的上下文。

Classic ASP, VBScript context.

很多文章,包括此Microsoft 1 ,说你的不能使用FileSystemObject的读取统一code文件。

A lot of articles including this Microsoft one, say you cannot use FileSystemObject to read Unicode files.

我遇到过这个问题而回,所以转用替代的ADODB.Stream,每READTEXT例子的这里,而不是使用的 FileSystemObject.OpenTextFile (它接受一个最后一个参数指示是否打开该文件作为UNI code,但实际上不工作)。

I encountered this issue a while back, so switched to using ADODB.Stream instead, per the ReadText example here, instead of using FileSystemObject.OpenTextFile (which does accept a final parameter indicating whether to open the file as unicode, but actually doesn't work).

然而,试图读取一个文件共享UNC(权限相关的问题)的文件时导致的ADODB.Stream在痛苦的世界。因此,调查这个,我碰到下面的办法,与UNI code文件工作的)迷迷糊糊的,b)可通过UNC文件共享:

However, ADODB.Stream results in a world of pain when trying to read a file on a UNC fileshare (permissions-related issue). So, investigating this, I stumbled across the following approach which works a) with unicode files, and b) across UNC fileshares:

dim fso, file, stream
set fso = Server.CreateObject("Scripting.FileSystemObject")
set file = fso.GetFile("\\SomeServer\Somefile.txt")
set stream = file.OpenAsTextStream(ForReading,-1) '-1 = unicode

这是一个使用FSO阅读没有任何明显的问题单code文件,所以我很困惑,所有引用,包括MS,说你不能使用FSO来读取UNI code文件。

This is using the FSO to read a unicode file without any apparent problem, so I'm confused as to all the references, including MS, saying you can't use the FSO to read unicode files.

有没有其他人采用这种方法读取单code文件?是否有任何隐藏的陷阱我的思念,或者你真能​​实际读取使用FSO UNI code文件?

Has anyone else used this approach for reading unicode files? Are there any hidden gotchas I'm missing, or can you really actually read unicode files using FSO?

推荐答案

是的,这文档过时。该脚本组件并通过一组处于初期阶段的变化(其中一些被打破的变化,如果你正在使用早期绑定),但是因为至少WK2000 SP4和XP SP2就已经很稳定。

Yes that documentation is out of date. The scripting component did go through a set of changes in its early days (some of them were breaking changes if you were using early binding) however since at least WK2000 SP4 and XP SP2 it has been very stable.

只是要小心,你通过UNI code的意思。有时候这个词UNI code用于更广泛,可以覆盖单code的任何编码。 FSO不读的单code的例子UTF8编码。对于您需要依傍的ADODB.Stream。

Just be careful what you mean by unicode. Sometimes the word unicode is used more broadly and can cover any encoding of unicode. FSO does not read for example UTF8 encodings of unicode. For that you would need to fall back on ADODB.Stream.

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

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