B4J Question FileChooser

Walt

Member
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
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Complete code:
B4X:
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.
   MainForm.Show
   fc.Initialize
   Dim f As String = fc.ShowOpen(MainForm)
   If f <> "" Then
     TextArea1.Text = File.ReadString(f, "")
   End If
End Sub
 
Upvote 0
Top