-1

I am creating HTML5 type of application in Titanium Appcelerator. I have written code in order to creates text file using using titanium code which executes properly and create text file at /Users/demoUser/Library/Developer/CoreSimulator/Devices/FE1CF0AC-D5BD-4FAB-9615-C58D80B5A9C6/data/Containers/Data/Application/40686DB0-BFB0-4D01-98BB-9E5758C4976D/Documents/file.txt

Now I am having a html file i.e index.html which I am loading in titanium webview within same application. Now I want to access content of file.txt in a function created in .html file.

Anyone who has worked on anything like this before ? Or any help or suggestion regarding this would be appreciated.

Sagar Kalathil
  • 49
  • 2
  • 14

1 Answers1

0

You can read a file either from resources directory or application directory and render it in html page like below.

 var readContents;

var readFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'data.txt');

if (readFile.exists()) { readContents = readFile.read(); Ti.API.info('File Exists');
}

var docString = readContents.toString(); Ti.API.info('Contents = ' + docString);

var text_in_html = "<html><body><pre>" + docString + "</pre></body></html>";

// Create our Webview var myWV = Ti.UI.createWebView({ html:text_in_html, title:'Title goes here', left:0, right:0, top:0, bottom:0, loading: true
});

arun
  • 107
  • 6
  • 1
    Thanks for your valuable input arun. But what I want is that i want to read content of file located in applicationDataDirectory from html file itself. i.e I want to create function in index.html itself which directly read content from applicationDataDirectory. – Sagar Kalathil Nov 02 '15 at 05:37