B4J Question FileChooser


I've been trying to learn to use FileChooser and I've hit a wall.
I can get a filename and separate it from the path, and even separate the name and extension and put them back together into a revised filename.

What I have been unable to do is actually open the file and work with it.

Does anyone have some example code that uses FileChooser to say, select a text file and display it in a TextArea?

Thanks, Walt


B4X founder
Staff member
Licensed User
Longtime User
Complete code:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private TextArea1 As TextArea
   Private fc As FileChooser
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   Dim f As String = fc.ShowOpen(MainForm)
   If f <> "" Then
     TextArea1.Text = File.ReadString(f, "")
   End If
End Sub
Upvote 0