FILE.OpenOutput(Dir,File,Append) problem

Carlos Muniz

Member
Licensed User
Longtime User
B4X:
    Dim TRIP1 As String = "1234567890"
    Dim TRIP2 As String = "abcdefghij"
    Dim TRIP3 As String = "123 456 789"
    Dim TRIP4 As String = "abc abc abc"
    Dim FILE_SIZE As Double
    Dim text As String
       
    File.OpenOutput (File.DirInternalCache, "MyFile.txt", True)  <<<<------- APPEND FEATURE ON
       
    File.WriteString(File.DirInternalCache, "MyFile.txt", TRIP1)
    text = File.ReadString(File.DirInternalCache, "MyFile.txt")
    Log("text1  " & text)
   
    File.WriteString(File.DirInternalCache, "MyFile.txt", TRIP2)
    text = File.ReadString(File.DirInternalCache, "MyFile.txt")
    Log("text2  " & text)
   
   File.WriteString(File.DirInternalCache, "MyFile.txt", TRIP3)
    text = File.ReadString(File.DirInternalCache, "MyFile.txt")
    Log("text3  " & text)
   
    File.WriteString(File.DirInternalCache, "MyFile.txt", TRIP4)
    text = File.ReadString(File.DirInternalCache, "MyFile.txt")
    Log("text4  " & text)
  
    FILE_SIZE = File.Size(File.DirInternalCache, "MyFile.txt")
    Log("_______________________________file size " & FILE_SIZE)

This is a small example. The real case is that I am receiving 1000 strings (1,2KBytes each) and I need to
save the whole thing in one file, MyFile.txt, using Append feature which doesn't work. What can I do?

Thanx a lot.
 

DonManfred

Expert
Licensed User
Longtime User
File.OpenOutput (File.DirInternalCache, "MyFile.txt", True) <<<<------- APPEND FEATURE ON
You get an Outputstream back from this Command.

Use the Outputstream to write to that file. Remember to close the Outputstream after you wrote the Data,
 

MaxRosa

Member
Licensed User
Longtime User
Traduzindo o que o @DonManfred disse: você obtém um OutputStream e precisa gravar os arquivos a partir dele, além de ser necessário esperar a gravação para poder ler e trabalhar com o arquivo resultante como disse o @agraham.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…