Is There way to write to a text file direct without Stream
I am using a %GlobalStream to create as % stream.Object and writing that to a file but for some reason when I run that on the terminal I get <PARAMETER>zWrite^%Library.GlobalCharacterStream.1 and no file is created
I have tried the following here is my code and still get the same result any help appreciated
ClassMethod WriteNodes(myfile As %String) { set status=##class(%XML.TextReader).ParseFile(myfile,.textreader) set ptemp=##class(%GlobalCharacterStream).%New() //check status if $$$ISERR(status) {do $System.Status.DisplayError(status) quit} //iterate through document, node by node while textreader.Read() { Do ptemp.Write("Node ", textreader.seq, " is a(n) ") Do ptemp.Write( textreader.NodeType," ") If textreader.Name'="" { Do ptemp.Write( "named: ", textreader.Name) } Else { Do ptemp.Write( "and has no name") } Do ptemp.Write( " path: ",textreader.Path) If textreader.Value'="" { Do ptemp.Write( " value: ", textreader.Value) } } set adapter = ##class(%File).%New("C:\IT\50_TestIn\warddata1.txt") set status = adapter.Write(ptemp) /* set tStream=##class(%Stream.FileCharacter).%New() set pInput=##class(%Stream.Object).%New() set pInput=ptemp set ptemp="" set myfile="C:\IT\50_TestIn\warddata1.txt" Set tStatus =tStream.LinkToFile("Myfile") do tStream.Write(pInput) */ }
[@ vitaliy.Serdtsev] have change my code as per your suggestion still not writing to a file I get <PARAMETER>zWrite^%Stream.FileBinary.1
Thanks missed the Do ptemp.WriteLine()
The method Write expects one parameter but you pass a few, and therefore an error occurs.
The following corrected code works for me: