简体   繁体   中英

Read Write text file using HTML code in Titanium Appcelerator

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 ie 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.

您可以从资源目录或应用程序目录读取文件并将其呈现在如下所示的 html 页面中。

 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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM