如何在客户端使用 GWT 将文本写入文件?
Is there any way to implement write/read file with gwt on client-side?
I tried with java.io.File, java.io.Writer ... I couldn't succeed.
thx in advance!
Update: Please see my own answer for a solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,您不能在客户端写入文件。 GWT 仅绑定 Java 语言的一个子集。任何文件 IO 都需要通过 RPC 或某种 Web 服务在服务器端进行。
No, you can't write to files on the client-side. GWT only binds a subset of the Java language. Any file IO would need to happen on the server side through RPCs or some kind of web service.
在某些现代浏览器中使用 HTML5 可以实现这一点。尝试lib-gwt-file。该库可以从客户端计算机读取文件,甚至支持 DND。要查看其实际效果,请点击此链接< /a>.
有关 HTML5 FileAPI 的更多信息,您可以在规范中找到。
要将文件从浏览器内存下载到客户端计算机,您可以使用数据 URI。示例如下此处。但此功能仅 Google Chrome 支持。另请查看以下有用的功能。它无需重新加载当前页面即可运行下载:
另一种半跨浏览器方式是 Downloadify。它是基于闪存的。检查此示例。
It's possible with HTML5 in some modern browsers. Try lib-gwt-file. This library can read files from client computer and even supports DND. To see it in action follow this link.
More information on HTML5 FileAPI you can find in the specification.
To download a file from browser memory to the client computer you can use Data URI. Example is here. But this feature is supported by Google Chrome only. Also take a look at the following helpful function. It runs download without reloading current page:
Another semi-crossbrowser way is Downloadify. It's based on flash. Check this example.
最近,我偶然发现了一个名为 client-io 的库。
Recently, I've stumbled upon a library called client-io.
在 GWT 中,客户端文件夹中的类仅编译为 javascript,因此无法使用
,因为 GWT 不提供包的编译
因此您必须仅通过 RPC 写入文本文件。
In GWT the classes in the client folder are only compiled into javascript hence it is not possible to use
since GWT does not provide compilation of the package
Hence you have to write text file through RPC only.