Can't open file in Android

Monkey Targets Forums/Android/Can't open file in Android

Lindsay(Posted 2014) [#1]
So this code works fine in iOS but on android gives me an error when the app runs: "Unfortunately ... has stopped" ...

Strict

#BINARY_FILES += "*.idx"

Import brl.filestream

Function Main:Int()
	Local packedFile: FileStream

	Local path: String = "monkey://data/languages/english.idx"
	
	' On android, this causes the app to stop ...
	packedFile = New FileStream(path,"r")
	
	Print "File opened"
	
	packedFile.Close()

	Return 0
End


You can download it here, along with the data file. I tried making the data file a .bin and even a .txt but still no luck. Any ideas?

Thanks,
Lindsay


programmer(Posted 2014) [#2]
Supported resource path prefixes:
http://www.monkey-x.com/docs/html/Programming_Resource%20paths.html


Danilo(Posted 2014) [#3]

So according to the table, we need to use LoadString or DataBuffer.Load to load "monkey://data/languages/english.idx".
FileStream is only supported for file = monkey://internal/ (and not with all targets).
Strict

#BINARY_FILES += "*.idx"

Import mojo.app
Import brl.databuffer

Function Main:Int()
    Local path: String = "monkey://data/languages/english.idx"

    Local s1:String = LoadString(path)
    Print s1.Length
    
    Local buff:DataBuffer = DataBuffer.Load(path)

    If buff
        Print "File opened"
        Print buff.Length
    Endif
    
    Return 0
End



Lindsay(Posted 2014) [#4]
Cross-platform development is a PITA, isn't it!

Thanks guys, changing to a databuffer has solved it :)