通过套接字将 Java 文件对象发送到服务器
您好,我正在尝试通过套接字将 Java 文件对象发送到服务器,然后服务器将其存储在数据库中。目前我已经创建了一个 FileBean,其中存储 File 对象。然后,我使用 ObjectOutputStream 将 FileBean writeObject() 到服务器。然而,似乎 File 对象只包含对实际数据的引用,因此服务器无法实际获取数据。
有没有办法使用对象输出流之类的东西序列化要通过套接字发送的文件对象?或者这是否需要将文件写入缓冲区并通过套接字发送?
任何帮助和代码示例都是值得赞赏的
Hello I am trying to send a Java File Object over a socket to a server which will then store it in a database. Currently I have created a FileBean which stores the File object in it. I then use an ObjectOutputStream to writeObject() the FileBean to the Server. However, it seems as though the File object only contains a reference to the actual data, so the Server fails to actually get the data.
Is there a way to serialize the File object to be sent over the socket using something like an objectoutput stream? or does this require to writing of the file into a buffer and sending that across the socket?
any help and code examples is apprecaited
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件就是路径,仅此而已。对于另一台机器上的服务器来说完全没有价值。
这是文件的所有状态(取自
java.io.File
的 Java 1.6 源代码):您必须读取文件的内容(可能作为字节数组)并将它们发送到服务器。
A file is a path, not much more. And totally worthless to a server on a different machine.
This is all the state a file has (taken from the Java 1.6 source of
java.io.File
):You will have to read the file's contents (probably as a byte array) and send them to the server.