HTML5从IPad文档目录中读取文件

时间:2023-02-06 12:25:58

I have created html5 based app in Titanium for ipad. Using Titanium I have stored a file named demo.txt in

我在Titanium for ipad中创建了基于html5的应用程序。使用Titanium我已经存储了一个名为demo.txt的文件

/Users/anonymous/Library/Developer/CoreSimulator/Devices/FE1CFXXX0AC-D5BD-9615-C58D80B5A9C6/data/Containers/Data/Application/2D25XXXX-4687-B28A-1EA7B7EA3013/Documents/

in same application itself. Now I need to want to access content of demo.txt in my index.html. Anyone having idea regarding this please help me out.

在同一个应用程序中。现在我需要在index.html中访问demo.txt的内容。有任何想法的人请帮助我。

3 个解决方案

#1


0  

You can use similar technique to read a file:

您可以使用类似的技术来读取文件:

var pagesDetailFile = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "demo.txt"); 
alert(pagesDetailFile.read()); // Read the file
pagesDetailFile = null; // remember to release the file

You should read the documentation carefully for available functions.

您应该仔细阅读文档以了解可用的功能。

#2


0  

You will have to use the techniques described at https://appcelerator.github.io/appc-docs/platform/latest/#!/guide/Communication_Between_WebViews_and_Titanium to fire an event in the WebView HTML which you'd pick up in Titanium JS, get the file and then use evalJS or fireEvent to send it back to the WebView HTML.

您将必须使用https://appcelerator.github.io/appc-docs/platform/latest/#!/guide/Communication_Between_WebViews_and_Titanium中描述的技术来触发您在Titanium JS中获取的WebView HTML中的事件,获取文件,然后使用evalJS或fireEvent将其发送回WebView HTML。

#3


0  

I used jquery in order to read data from the simulator and it works for devices too.

我使用jquery来从模拟器中读取数据,它也适用于设备。

var filePath = "/Users/anonymous/Library/Developer/CoreSimulator/Devices/FE1CFXXX0AC-D5BD-9615-C58D80B5A9C6/data/Containers/Data/Application/2D25XXXX-4687-B28A-1EA7B7EA3013/Documents/admin/content.txt";
$.ajax({
    url: filePath,
    context: document.body,
    async: false,
    success: function(response){
        Ti.API.info("FILE CONTENT " + response);
    },
    error: function(data){
        alert('does not exist');
    }
});

filePath is actual path in which we are storing data.

filePath是我们存储数据的实际路径。

#1


0  

You can use similar technique to read a file:

您可以使用类似的技术来读取文件:

var pagesDetailFile = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "demo.txt"); 
alert(pagesDetailFile.read()); // Read the file
pagesDetailFile = null; // remember to release the file

You should read the documentation carefully for available functions.

您应该仔细阅读文档以了解可用的功能。

#2


0  

You will have to use the techniques described at https://appcelerator.github.io/appc-docs/platform/latest/#!/guide/Communication_Between_WebViews_and_Titanium to fire an event in the WebView HTML which you'd pick up in Titanium JS, get the file and then use evalJS or fireEvent to send it back to the WebView HTML.

您将必须使用https://appcelerator.github.io/appc-docs/platform/latest/#!/guide/Communication_Between_WebViews_and_Titanium中描述的技术来触发您在Titanium JS中获取的WebView HTML中的事件,获取文件,然后使用evalJS或fireEvent将其发送回WebView HTML。

#3


0  

I used jquery in order to read data from the simulator and it works for devices too.

我使用jquery来从模拟器中读取数据,它也适用于设备。

var filePath = "/Users/anonymous/Library/Developer/CoreSimulator/Devices/FE1CFXXX0AC-D5BD-9615-C58D80B5A9C6/data/Containers/Data/Application/2D25XXXX-4687-B28A-1EA7B7EA3013/Documents/admin/content.txt";
$.ajax({
    url: filePath,
    context: document.body,
    async: false,
    success: function(response){
        Ti.API.info("FILE CONTENT " + response);
    },
    error: function(data){
        alert('does not exist');
    }
});

filePath is actual path in which we are storing data.

filePath是我们存储数据的实际路径。