Java socket EOFException

半世苍凉 提交于 2019-12-01 15:31:08

FileNotFoundException has two meanings:

  1. On input, the file wasn't found, couldn't be opened due to permissions, etc.
  2. On output, the target directory wasn't found, couldn't be written into due to permissions, etc.

For example if the filename you are sending contains a directory that doesn't exist at the server, you will get FileNotFoundException from new FileOutputStream.

There isn't enough (i.e. any) information in your question to say any more about that.

However:

  • You don't need object streams for this, or even data input/output streams. You're only using the basic read() and write() methods, so you may as well just use the socket streams directly.

  • You should use a larger buffer than 1024 bytes, say 8192 or a multiple thereof.

  • You can send multiple files per connection via the technique given in my answer to this question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!