【问题标题】:VBScript create and open a new fileVBScript 创建并打开一个新文件
【发布时间】:2015-05-03 23:56:12
【问题描述】:

我尝试在 VBScript 中为 PowerAMC 制作脚本。 我有一个错误。

我检查了所有元素以制作包含内容的文件(XSD 文件):

private Sub writeInFile(pathFolder, pathFile, val)
  Output "WriteInFile["&pathFolder&pathFile&"]"
  Dim fso, MyFile
  Set fso = CreateObject("Scripting.FileSystemObject")

  Set MyFile = fso.CreateTextFile(pathFolder&pathFile, true)
  If (fso.FileExists(pathFolder&pathFile)) Then
    MyFile.WriteLine(val)
  Else
    ouput "File can't be create"
  End If

  MyFile.Close
  end Sub

并且该文件存在的内容很好,但如果我尝试阅读它:

public Function readFile(path)
  'Declare variables
  Dim objFSO, objReadFile, contents

  'Set Objects
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objReadFile = objFSO.OpenTextFile(path, 1, false)

  'Read file contents
  contents = objReadFile.ReadAll

  'Close file
  objReadFile.close

  'Cleanup objects
  Set objFSO = Nothing
  Set objReadFile = Nothing

  readFile = contents
   End Function

我明白了:“ÿþ

【问题讨论】:

标签: vbscript


【解决方案1】:

我认为问题来自 Unicode 格式, 看看这个 => FileSystemObject - Reading Unicode Files

【讨论】:

  • 我已经解决了这个问题: Set oReadfile = FS.OpenTextFile(sFile, 1, False, True) 真正的参数修复了这个错误,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多