2015-10-29 23 views
-1

我在Titanium Appcelerator中創建HTML5類型的應用程序。我寫了代碼,以創建使用正確執行的鈦代碼創建文本文件,並創建文本文件在/Users/demoUser/Library/Developer/CoreSimulator/Devices/FE1CF0AC-D5BD-4FAB-9615-C58D80B5A9C6/data/Containers/Data/Application/40686DB0-BFB0-4D01-98BB-9E5758C4976D/Documents/file.txt使用Titanium Appcelerator中的HTML代碼讀取寫入文本文件

現在我有一個html文件,即index.html,我在同一個應用程序中鈦webview加載。現在我想要在.html文件中創建的函數中訪問file.txt的內容。

以前曾經從事過類似工作的人嗎?或者有關這方面的任何幫助或建議,將不勝感激。

回答

0

您可以從資源目錄或應用程序目錄中讀取一個文件,並將其顯示在如下所示的html頁面中。

var readContents; 

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

​​

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

+1

感謝您的寶貴意見阿倫。但我想要的是,我想從html文件本身讀取位於applicationDataDirectory中的文件的內容。即我想在index.html自身中創建函數,它直接從applicationDataDirectory讀取內容。 –