Writing and Reading to/from text files

Kamac

Active Member
Licensed User
Longtime User
Hi.


Could someone give me straight-forward two examples of writing and reading to/from text files?

1. Write "a" to text file called "text.txt"
2. Read all strings from "text.txt" and store them into array.

@additional 3. After doing 1, how to add another "a" to "text.txt" so it'll contain "a
a"

- basically, extending "text.txt" in more strings.
 

klaus

Expert
Licensed User
Longtime User
- Run the AVD Manager
- Setup the Emulator
- In the Hardware part, click on 'New' (picture 1)
- You will see SD Card support, click on 'OK' (picture 2)
- That's it (picture 3).

Best regards.
 

Attachments

  • EmulatorSDCard1.jpg
    EmulatorSDCard1.jpg
    39.5 KB · Views: 275
  • EmulatorSDCard2.jpg
    EmulatorSDCard2.jpg
    24.3 KB · Views: 305
  • EmulatorSDCard3.jpg
    EmulatorSDCard3.jpg
    29.9 KB · Views: 263
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
Ok, i'll take a look on it. Why may this not work?

B4X:
   Dim random As Int
   random = Rnd(1,2)
   RemoveViews
   Activity.LoadLayout("newmonster")
   If(mResult == "Dot") Then
      Monster.Bitmap = LoadBitmap(File.DirAssets,"egg.gif")
      MonsterType.Text = "1st SPECIAL Monster"
   Else If(random == 1) Then
      Monster.Bitmap = LoadBitmap(File.DirAssets,"bird.gif")
      MonsterType.Text = "Some Bird"
   Else If(random == 2) Then
      Monster.Bitmap = LoadBitmap(File.DirAssets,"creature.gif")
      MonsterType.Text = "You've got an CREATURE"      
   End If

it's always giving me out
B4X:
   Else If(random == 1) Then
      Monster.Bitmap = LoadBitmap(File.DirAssets,"bird.gif")
      MonsterType.Text = "Some Bird"

but

B4X:
   If(mResult == "Dot") Then
      Monster.Bitmap = LoadBitmap(File.DirAssets,"egg.gif")
      MonsterType.Text = "1st SPECIAL Monster"

is special and it works for certain things.

What i mean is that variable random is always equal to 1.
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
Okay i got it.




My last problem, but related to that topic. I will make it short:

Can i make an .txt to my app which i can store strings into it, but i can also view it to see the result?



Example.

Make an text file, store "a" to it.


Now i can see that text file, next to my .apk or in Files folder.
 
Upvote 0
Top