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.
You can read a file either from resources directory or application directory and render it in html page like below.
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});