How easy to read and write from file on Android
Monkey Forums/Monkey Beginners/How easy to read and write from file on Android
| ||
Or would it be easier to take the plunge into developing an online database that folk could upload their data to that a HTML5 app could access... I know the whole nausea that could be entailed within the statement I nonchalantly made there (JSON, cheeky bit of mysql amongst other things) - I'd love to just access raw files that I've parsed on an Android device for local use. This seems like a good jumping off point: http://www.monkey-x.com/Community/posts.php?topic=8696&post=90465&view=all#90465 This is exciting.... [EDIT] Whilst I've initially achieved stuff quite quickly in HTML5, should I stop with my HTML5 and instead focus upon more Android esque dev? Or stay on the HTML5 bus for a while longer until I'm ready to hop on the Android dev bus? |
| ||
Do you have an Android device for testing? By read/write a file you mean a local file system for single player? HTML5 supports saving and loading data locally too but not all the same filesystem features other targets support. What exactly are your goals? |
| ||
Hi Soap, My goal is to read a .tcx file type, parse the data, store it in my own array(s) and plot some graphs. I'm carrying on with HTML5 development at the moment (still very early days) - I have an ASUS Android tablet for testing purposes - although the driver just failed to install for it which is of concern. Still, onwards and upwards. I suppose as an alternative to accessing a tcx file locally (which I intend to do for development purposes in the first instance) the aspiration maybe to access files remotely, say within a dropbox account. Ambitious I know.... |
| ||
As far as I remember, for Android, you have to handle storage as one long string with SaveString and LoadString. Unless that has been changed during any recent updates of course. |
| ||
Here's a loader class that I made quite a while back, I've used it in Flash and HTML5 targets so far, but I don't see any reason why it shouldn't work on Android. I will get around to adding a save method at some point when I feel the need to, but it shouldn't be too hard to do that yourself if you can't wait. Class C_FileLoader Field fileData:String[] Field currentLine:Int Method New(fileName:String) fileData = LoadString(fileName).Split("~n") currentLine = 0 End Method ReadLine:String() Local currentData:String if Eof() = False currentData = Self.fileData[Self.currentLine] currentLine = (currentLine + 1) Else currentData = "Data Exhausted!" EndIf Return currentData.Trim() End Method Eof:Int() if Self.currentLine > (fileData.Length() - 1) Return 1 Else Return 0 EndIf End Method LineCount:Int() Return Self.fileData.Length() End Method ByteCount:Int() Local bytes:Int = 0 Local line:Int For line = 0 To (Self.fileData.Length() - 1) bytes = (bytes + Self.fileData[line].Trim().Length()) Next Return bytes End Method Empty:Void() Local counter:Int For counter = 0 to (fileData.Length() - 1) fileData[counter] = "" Next fileData = fileData.Resize(0) End End |
| ||
If what I posted above don't work then look into SaveState and LoadState. You will have to handle things a lot differently with those commands though. |