Android Question : Trying to access the File.DirRootExternal and File. DirDefaultExternal

MarkS

New Member
Licensed User
Longtime User
I am new to B4A. I am trying to write to a file using the File.OpenOutput and File.WriteString method using the directories above. I have tried both, but my file does not get created, as when I print out the contents of the directory, it lists: /storage/emulated/0 for File.DirRoot External and /storage/emulated/0/Android/data/b4aexample/files.
I am connected wireless using b4abridge. Do these directories only get populated with the storage card root folder and the default folder for my application in the released version?
 

MarkS

New Member
Licensed User
Longtime User
No. I just used the msgbox to display the contents of the two file properties and got the above values.
 
Upvote 0

MarkS

New Member
Licensed User
Longtime User
I am opening the file for append, so that it should get created if it doesn't exist and append to the file if it does.
My code:

dim datastring as string
datastring = "02/15/15,01:00,03:00,567,testing equipment"
File.OpenOutput(File.DirRootExternal,"mydata.txt",1)
File.WriteString(File.DirRootExternal,"mydata.txt", datastring)

I have also tried the File.DirDefaultExternal in place of File.DirRootExternal and it doesn't give me the results I think it should or write the file anyplace on my device.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
File.OpenOutput(File.DirRootExternal,"mydata.txt",1)
will open an outputstream. You need to put data into this outputstream to get them written to the file.
File.WriteString will open the file, writes the text to it and close it. the file will be overwritten if already existing.
 
Upvote 0

MarkS

New Member
Licensed User
Longtime User
will open an outputstream. You need to put data into this outputstream to get them written to the file.
File.WriteString will open the file, writes the text to it and close it. the file will be overwritten if already existing.

I got the file to write to the directory using the file.writestring, but then realized I needed to append to the file if it exists, next time I run my app. So here is my code now:

dim datastring as string
dim writer as textwriter
datastring = "this is what I want written to the file"
writer.Initialize(File.OpenOutput(File.DirDefaultExternal, "TimeData.txt", True))
writer.Writeline(datastring)
writer.Close

This does not give me an error, but it does not append/write the data to the file. It does not create the file if it doesn't exist either.
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…