写入远程文件并将字符串转换为 url
我想写入远程文件并读取远程文件的内容。我的字符串就像 http://www.mywebsite.info/other/poll.txt
。如何将此字符串转换为 URL/URI ?我的目标是写入和读取服务器上托管的文件的内容。 (通过小程序)
我可以使用 FileReader
和 FileWriter
来实现此目的吗?
I want to write to a remote file as well as read the contents of a remote file. My string is like http://www.mywebsite.info/other/poll.txt
. How to convert this string into URL/URI ? My goal is to write as well as read the contents of the file hosted on my server. (via applet)
Can i use FileReader
and FileWriter
for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的阅读方式 -
Try something like this for reading -
FileReader 和 FileWriter 用于从文件系统读取文件或向文件系统写入文件。
Applet 使用 HTTP 与其源服务器通信。 HTTP 并不是用于读写文件的协议。要读取它,您需要打开到此 URL 的 HttpUrlConnection。要编写它,您需要有一些服务器组件(PHP 应用程序、Servlet 等)并向该服务器组件发送适当的请求,以便它写入文件。
在尝试编写小程序之前,请先了解 HTTP 的工作原理。
FileReader and FileWriter are used to read and write files from/to the file system.
An applet communicates with its origin server using HTTP. And HTTP isn't a protocol used to read and write files. To read it, you need to open a HttpUrlConnection to this URL. To write it, you'll need to have some server component (a PHP application, a Servlet, whatever) and send an appropriate request to this server component so that it writes to the file.
Read up on how HTTP works before trying to write your applet.