Probleme TextOutputStream.Create

Bonjour TextOutputStream.Create me pose problème sur un Mac/Monterey

A la deuxième exécution, j’ai une erreur 24

Merci pour votre éclairage

Var d As  DateTime
Var tx As String 
Var s As String = System.Random.InRange(0, 100).ToString 
Var f As FolderItem

d = DateTime.Now  
f = SpecialFolder.Desktop.Child ( "ee" )
If f.Exists = False Then
  f.CreateFolder
End If
d = DateTime.Now  
f = SpecialFolder.Desktop.Child ( "ee" ).child ( s + ".txt" )
If f.Exists Then
  f.Remove
End If
If f <> Nil Then
  Try
    Var t As TextOutputStream 
    t = TextOutputStream.Create(f)
    t.WriteLine( "zz" + d.SQLDateTime )
    t.Close
  Catch e As IOException
    tx = e.Message + " / " + Str ( e.ErrorNumber )
    tx = tx
  End Try
End If
 

poopipoipo

Where do you get the error? What is the purpose of your code?

I think that at the second try the file already exists. If you use a BinaryStream instead of a TextOutPutStream then you can overwrite existing files.

Thank you very much for the answer

The error is returned by TextOutputStream.Create

The file does not exist on the disk because the
f.CreateFolder
removes it.

I tried “BinaryStream”, there are no more mistakes.

I posted a test code which is the example of documentation.

Merci Béatrix

CreateFolder ? tu crée un dossier et tu veux écrite du texte dedans ?

De toute façon, TextOutputStream.Create efface l’ancien fichier (s’il y en a un). Vérifie dans la documentation (si API2 fait ça aussi).

I have several bug reports from customers where code
f.remove
does not remove the existing file immediately.
Adding a 1/2 second delay helped.

From TextOutputStream.Create:

If the file exists, it will be erased and recreated.

Je veux creer un dossier s il n existe pas puis creer un fichier.txt pour ecrire dedans

TextOutputStream.Create efface effectivement si le fichier existe

these lines are not mandatory because the file name is created in a random way
but I test this

Mauvaise interprétation…

Ceci dit, f écrit dans SpecialFolder.Desktop.Child(“ee”), etc.

Normalement, tu devrais avoir un fichier texte (vide) sur le bureau, dans un dossier nommé **ee**

Relit ton code complètement. (il y a des redondances)

Ajoute un Break à la ligne ```
If f <> Nil Then

et suit l’avancée de ton code dans le debugger…

Merci beaucoup a tous pour vos contributions.
Il s’agissait d un probleme sur le disque !
Solution: formatage + instal system + instal xojo …