在 GWT 中读取客户端文件
我想读取文件的内容并将其存储在数组中。 我有一个使用 formPanel 和 formupload 浏览文件的代码。
如何读取文件并存储在数组中。
任何示例代码都会有很大的帮助。
I want read the content of file and store it in array.
I have a code to browse a file using formPanel and formupload.
How to read a file and store in array.
Any sample code will be of great Help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 HTML5 文件阅读器。像这样的事情:
You can use the HTML5 file reader. Something like this:
GWT 客户端代码只是 JavaScript,并且受到与浏览器沙箱模型中任何常规 JavaScript 相同的限制。
也就是说,JavaScript 无法从任何浏览器访问本地文件。
文件对话框以及由此产生的到服务器的传输由浏览器处理,并且不能以任何方式供 JavaScript 代码使用。
您必须将文件上传到服务器,然后在服务器上处理该文件,并通过将数据从服务器发送回客户端来显示您需要显示的内容。
GWT client code is simply JavaScript and is constrained by the same limitations that any regular JavaScript would be subject to in the browsers sandbox model.
That is to say no local file access is available to JavaScript from any browser.
The file dialog box and the resulting transfer to the server is handled by the browser and is not available to the JavaScript code in any fashion.
You would have to upload the file to a server and then process the file on the server and display what you needed to display by sending the data back to the client from the server.
尝试使用 GWT 中的元素库:
http://www.gwtproject.org/articles/elemental.html< /a>
将文件内容读取到 txtArea 的示例代码(所有客户端站点):
本教程可能也有用:
http://www.instantshift.com/2013/ 11/19/html5-features-with-gwt-elemental/
Try use elemental library from GWT:
http://www.gwtproject.org/articles/elemental.html
Example code reading file content to txtArea (all client site):
This tutorial may be also useful:
http://www.instantshift.com/2013/11/19/html5-features-with-gwt-elemental/
1) 将文件上传到您的服务器(例如使用 gwt-upload)
2) 然后从客户端向服务器发出请求以检索文件的字节
1) Upload the file to your server (using gwt-upload for example)
2) Then make a request from your client to the server to retrieve the bytes of the file
您可以使用 Flash 或 Java Applet 在客户端完成所有操作。但这些都是复杂的,而且可能不是非常漂亮的解决方案。
看一下 GwtAI 在 GWT 中的 Java Applet 集成:
http://code.google.com/p/gwtai/
You could use Flash or a Java Applet to do it all client-side. But those are complicated and probably not very beautiful solutions.
Have a look at GwtAI for Java Applet integration in GWT:
http://code.google.com/p/gwtai/