Jump to content
COMFIED

Reading Text File Located in /res Folder

Recommended Posts

On my local browser (Chrome and IE),

the demo works for remote JSON file

but does not work with the local file inet.txt - the Download('res/inet.txt'); does not fire status 200 and the file doesn't download/ doesn't display.

Share this post


Link to post
Share on other sites

What about read & write to the \res folder?  Is that possible?

e.g., let's say you want to work with something similiar to an INI file? Or read in and write out a JSON file, or an XML file?

For security reasons this is not possible. You cannot create files on the client side, you don't have write permission in that environment. A work around is sending the data you want to store through http requests to the web server, which in turn you can generate a .txt file for the user to download.

Share this post


Link to post
Share on other sites

So, I will need to use a local storage method? Is there something particularly better for iOS and Android (or compatible with all browsers)?

 

I need to write a list of multiple strings

 

e.g. Mountain, Date,  Note

 

is JSON the best choice?

 

 
{"completed":[
    {"mountain":"Mount Marcy", "date":"01/15/2016", "note":"Hiked with friends, Debby, Danny, and Rob on a brisk cold day, hovering at around -1 degrees f},
    {"mountain":"Algonquin Peak", "date":"01/22/2016", "note":"Gorgeous day to hike. Took the dogs (gizmo and marley). They did great!"},
    {"mountain":"Mount Haystack", "date":"02/03/2016", "note":"Stayed at John's brook lodge the night before."}
]}

Share this post


Link to post
Share on other sites

In my own apps written in Smart Mobile Studio I've been using the local storage with JSON data successfully. However, this type of storage is limited in size. It's often about 5 MB, but you never know.

 

This said, you probably want to use Cordova or PhoneGap to build native-like hybrid web apps. Doing so you have better control over the size constraints. If this isn't still enough you can also use the cordova file plugin to hook into the native file system. I've not yet used this on my own, but judging from the overall quality of official cordova plugins this should work flawlessly.

 

UPDATE: I forgot to mention thath the cordova file plugin is based on the W3C File API, so chances are high that this approach will soon be available (in some form) in all browsers.

Share this post


Link to post
Share on other sites

Here's a brief example on how to use it:

uses
  W3C.WebStorage;

type
  JData = class external
    Value: Integer;
  end;

// store data
var TempData: Variant = new JObject;
TempData['Value'] := 1;
Window.LocalStorage.setItem('IdentifierOfChoice', JSON.Stringify(TempData));

// load data
var Data := JData(JSON.Parse(Window.LocalStorage.getItem('IdentifierOfChoice')));

I can probably be written in a more elegant way, but it works fine for my needs.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...