Android Question File.WriteString Problem

wdegler

Active Member
Licensed User
Longtime User
To anyone with an explanation:

I clicked on Help/Online Help, selected File/WriteString and copied the example:

File.WriteString(File.DirRootExternal, "1.txt", "Some text")

into a program as the first statement after the LoadLayout line.
I then set a breakpoint on the line after that. After I clicked on Project/Compile & Run,
the program stopped at the breakpoint and the following run time error message appeared:

java.io.FileNotFoundException: /mnt/sdcard/1.txt (Permission denied)

Why doesn't WriteString work here?
 

wdegler

Active Member
Licensed User
Longtime User
Note that the permission is added automatically when you access File.DirRootExternal.

You can check whether the external storage is writable with File.ExternalWritable.

I added this File.ExternalWritable line as you suggested. It responded with False.
I am running this app in the Debug mode using the built-in virtual device manager.

I have written and published previous apps with a File.WriteString(File.DirRootExternal, "1.txt", "Some text") kind of statement without a problem.
Could the fact that they were compiled with a previous version of B4A be a factor?

I find that there is no problem when I use File.DirInternal in place of File.DirRootExternal.
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Have you defined a virtual SDCard for your emulated device?
Have you defined a virtual SDCard for your emulated device?

Thanks. I haven't thought of that before.
One of my previous apps (published), contains all of the following lines which work as intended:

File.WriteString(File.DirRootExternal,"Settings.txt",DefSetting)

File.WriteList(File.DirRootExternal,"Log.txt",LogLst)

If File.Exists(File.DirRootExternal,"Settings.txt") Then
Settings=File.ReadString(File.DirRootExternal,"Settings.txt")
Else
File.WriteString(File.DirRootExternal,"Settings.txt",DefSetting)

Settings=DefSetting
EndIf

LogLst=File.ReadList(File.DirRootExternal,"Log.txt")

File.Delete(File.DirRootExternal,"Log.txt").


I see in the documentation that DirRootExternal, DirInternal and DirDefaultExternal are labeled as read only. ???
 
Upvote 0
Top