使用Java复制文件字节是否等同于复制整个文件?

时间:2015-11-26 08:32:23

标签: java sockets video javafx

我正在开发P2P视频共享应用程序。我正在使用RandomAccessFile类逐字节地读取文件的内容(.mp4视频),我正在使用套接字通过网络传输这些字节的块。在网络的另一端,我使用FileOutputStream将这些字节附加到文件中。使用文本编辑器打开时,汇编的文件看起来与原始文件相同。然而,JavaFX告诉我该文件已损坏。

3 个答案:

答案 0 :(得分:0)

  

使用Java复制文件字节是否等同于复制整个文件?

如果正确进行逐字节复制,文件应该相同。如果没有,很可能是你的代码错误...某处。

答案 1 :(得分:0)

这个文件应该是缩进的,但是你可能没有正确地完成文件,也许文件末尾有一些额外的字节,或者有一些缺少的字节。可能文件的末尾以某种方式被破坏,可能仅仅是最后一个字节。

答案 2 :(得分:0)

是的,文件应该是相同的,但在大多数情况下不建议使用字节进行字节复制。如果您要发送大块数据,也可以直接读取数据块。

此外,与其他提到的一样,您不应使用文本编辑器比较二进制文件的内容。您可以在Linux上使用Traceback (most recent call last): File "c:\python3.5\lib\runpy.py", line 170, in _run_module_as_main "__main__", mod_spec) File "c:\python3.5\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Python3.5\Scripts\scrapy.exe\__main__.py", line 5, in <module> File "c:\python3.5\lib\site-packages\scrapy\__init__.py", line 48, in <module> from scrapy.spiders import Spider File "c:\python3.5\lib\site-packages\scrapy\spiders\__init__.py", line 10, in <module> from scrapy.http import Request File "c:\python3.5\lib\site-packages\scrapy\http\__init__.py", line 15, in <module> from scrapy.http.response.html import HtmlResponse File "c:\python3.5\lib\site-packages\scrapy\http\response\html.py", line 8, in <module> from scrapy.http.response.text import TextResponse File "c:\python3.5\lib\site-packages\scrapy\http\response\text.py", line 13, in <module> from scrapy.utils.response import get_base_url File "c:\python3.5\lib\site-packages\scrapy\utils\response.py", line 12, in <module> from twisted.web import http File "c:\python3.5\lib\site-packages\twisted\web\http.py", line 92, in <module> from twisted.internet import interfaces, reactor, protocol, address File "c:\python3.5\lib\site-packages\twisted\internet\reactor.py", line 38, in <module> from twisted.internet import default File "c:\python3.5\lib\site-packages\twisted\internet\default.py", line 56, in <module> install = _getInstallFunction(platform) File "c:\python3.5\lib\site-packages\twisted\internet\default.py", line 50, in _getInstallFunction from twisted.internet.selectreactor import install File "c:\python3.5\lib\site-packages\twisted\internet\selectreactor.py", line 18, in <module> from twisted.internet import posixbase File "c:\python3.5\lib\site-packages\twisted\internet\posixbase.py", line 18, in <module> from twisted.internet import error, udp, tcp File "c:\python3.5\lib\site-packages\twisted\internet\udp.py", line 53, in <module> from twisted.internet import base, defer, address File "c:\python3.5\lib\site-packages\twisted\internet\base.py", line 23, in <module> from twisted.internet import fdesc, main, error, abstract, defer, threads File "c:\python3.5\lib\site-packages\twisted\internet\defer.py", line 29, in <module> from twisted.python import lockfile, failure File "c:\python3.5\lib\site-packages\twisted\python\lockfile.py", line 52, in <module> _open = file NameError: name 'file' is not defined cmp或在Windows上使用python NameError: name 'file' is not defined