there does not seem to be a Xojo example code to write a text file and then read it back? does anyone have such example code they could share? can the current android system do it?
see here
can the current android system do it?
you not have permissions to all files, but sandbox for your app enviroment should be ok.
if you uninstall app all data in this (sub)folder get lost.
Thank you Markus for your response. I am familiar with the nuts and bolts. The code I am bringing to android is well-tested in iOS. So I created my own little write-then-read app and put it in the open handler for the default screen1 of a new app. seems to work. cool.
Then when I paste the same code into a button handler in my actual app, it does not seem to work.
Hence my question if anyone is using files in android successfully. If this feels like a bug, I will report it. If it “should work,” I will keep fiddling.
Please share your sample project. Thanks
thank you for getting involved. enclosed are two files. the little one is the standalone code that works. the bigger one has the same code pasted into the handler of the Initialize button in the lower right of the screen that comes up. (Tablet landscape. I use the pixel tablet emulator.) I could not get a collected version to load. 250 Mbytes of mbs plugins plus hundreds of images. I don’t believe the code needs either. please let me know if it does not come up for you. I use 3.1.
JustKepler 14b with sample code.xojo_binary_project.zip (76.8 KB)
wow. I am not sure where to go with this, but it is certainly encouraging that the code works for you.
Since you’re getting an exception, you should look at its error number (and description, if it’s not empty). That would help in knowing what’s happening.
Is breedtrace.txt already open in some app that won’t allow it to be overwritten?
good thought. what it shows is “/data/user/0/com.selfschooling.keplertabsupport/files/BreedTrace.txt: open failed: EISDIR (Is a directory)” error number is 0. does this help us?
certainly does. It implies that instead of BreedTrace.txt being an existing file, it is a folder.
To resolve that you can try removing it before writing to it.
try
App.BreedTextFolderitem.remove
catch
end try
if App.BreedTextFolderitem.exists then
dim r as string = “Unable to remove the existing file”
if App.BreedTextFolderitem.isFolder then r = r + “ because it is a folder with contents”
msgbox r
end if
this just in. reinstalled Android Studio, replacing 2025.2.2.8 with 2025.2.3.9. now the simple example works for me, too. I will go ahead and see how things go for my actual code. my thanks to all for engaging with this problem.
(Android)
i remember in older xojo version it was not possible to overwrite a file, i had to delete it first.
folderitem have a useful method .Exists
your sample code design is not good.
you have used the if then but forgot the else part.
and few variables that should better start inside a method and not global.
dim and var inside a method are only in this method scope and after the method they disappear.
if your app need a static path for files its good to use a method that return the path folderitem if exists or create this path before and then return it.
you would have clear and less rows
var myfile As FolderItem = MyPath().Child("Text.txt")
if myfile.Exists then
else
end if
For reference, Xojo does include a sample project that demonstrates this: Platforms/Android/Framework/FolderItem



