Android Question Saving And reading Text Files(Solved)

Stichler

Active Member
Licensed User
I have a game that I want to save two basic pieces of info for resuming the game. They are LevelNumber and NumberOfHints. I can not seem to get this to work at all. I tried running just the following code to see if I can write anything and I'm getting the error that follows that

Code:
File.WriteString(File.DirRootExternal, "String.txt", "1")

Error:

Error occurred on line: 40 (Level1)
java.io.FileNotFoundException: /storage/emulated/0/String.txt (Permission denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:287)
at java.io.FileOutputStream.<init>(FileOutputStream.java:223)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
at anywheresoftware.b4a.objects.streams.File.WriteString(File.java:263)
at b4a.example.level1._activity_create(level1.java:375)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.level1.afterFirstLayout(level1.java:104)
at b4a.example.level1.access$000(level1.java:17)
at b4a.example.level1$WaitForLayout.run(level1.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (level1) Resume **
 

Geezer

Active Member
Licensed User
Longtime User
The first line of the crash is the PERMISSION DENIED.

Try a search for runtime permissions.

Or better, save the file to DirInternal so you don't need permissions.
 
Upvote 0

Stichler

Active Member
Licensed User
If I save to DirInternal will it remain at all times? In other words when App exits, phone turns off etc? And ty by the way+
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The File.DirIntrenal folder is accessible only by the application and remains as long as the program remains on the device.
If you delete the program from the device, the File.DirIntrenal folder will be lost.
 
Upvote 0
Top