I would like to read the first line of a .txt file, for example composed as follows:
first line: Hello everyone
second line: how are you?
third line: Well you?
I would like to read the first line of a .txt file, for example composed as follows:
first line: Hello everyone
second line: how are you?
third line: Well you?
I would like to read the first line of a .txt file, for example composed as follows:
first line: Hello everyone
second line: how are you?
third line: Well you?
This will read all of the lines. You can just forget the loop if you want the first line only.
B4X:
Dim lReader As TextReader
lReader.Initialize(File.OpenInput([The folder where the file is], [The name of the file]))
Dim lLine As String
lLine = lReader.ReadLine
Do While lLine <> Null
lLine = lReader.ReadLine
Loop
lReader.Close
it works with the log, but when I use EditText it gives me an error: java.lang.RuntimeException: Object should first be initialized (EditText).
edittext is about the designer. my code is:
B4X:
Dim EditText1 As EditText
Dim list As List
list= File.ReadList(File.DirRootExternal, "/My Folder/textfile.txt")
EditText1.Text=list.Get(0)
If that means that your EditText is part of a layout file produced by the Designer you load before the shown code than you shouldn't declare it again in your code (i.e. remove the "Dim EdiText1.. line).
Dim myans() As String
myans = SplitText(File.ReadString(File.DirAssets,"myfile.txt"))
EditText1.Text = myans(0)
(note, I'm just repeating what @udg said).
Finally, EditText1 must be the correct object name, meaning, it is the same name given in your layout. So make sure your layout includes an EditText object/view that is named EditText1 (here I'm just repeating what @Mahares said).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.