[Closed] Writing a string to file in MaxScript
Well, now I know how to create/open a filestream, the user reference teaches us how to read the filestream.
but now ? how do I write a string to a filestream ?
[left]readLine <filestream>[/left]
[left]Read next line, return as string[/left]
[left]readChar <filestream>[/left]
[left]Read next char, return as string[/left]
[left]readChars <filestream> <char_count>[/left]
[left]Reads the specified number of characters and returns them in a string.[/left]
[left] [/left]
[left] [/left]
Where’s WriteChar <String> ?
For write in filestring I use:
txt = "insert your text"
f = (createFile "C://tmp.txt")
format txt to:f
But, I don’t get open and write a existing file
You can use both
print someString to:yourFileStream
and
format “%” someString to:yourFileStream
PRINT outputs the string including quotation makrs. FORMAT does not.
So if by “string” you mean a MAXScript string value including the quotes, use PRINT.
You can get the same behavior from FORMAT using
format “”%”” someString to:yourFileStream
There is a link at the bottom of the FileStream documentation page mentioning both as Associated Methods (because they are value common operators and not FileStream specific – you can use both with StringStream and WindowStream too)
Thanks ( once again ) for your time ! Your clear explanations are always very helpfull !
Try to open the file using openFile in “wt” mode and write text. It should work. I think your problem may comes from the fact you wanted to open a file not properly closed.