Java socket EOFException

前端 未结 1 828
轮回少年
轮回少年 2021-01-17 06:53

I use RMI and socket to transfer files between a client set. The problem is when running the code below sometimes i get this exception in client side :

相关标签:
1条回答
  • 2021-01-17 07:31

    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.

    0 讨论(0)
提交回复
热议问题