Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用套接字脱机读取字节文件-Java_Java_Sockets_Tcp - Fatal编程技术网

使用套接字脱机读取字节文件-Java

使用套接字脱机读取字节文件-Java,java,sockets,tcp,Java,Sockets,Tcp,我有一个包含tcp数据包的字节文件。我想使用套接字读取这些数据包 那么,是否可以使用套接字在没有连接的情况下读取此文件?否,但您可以使用FileInputStream并从文件中读取字节,如以下代码段所示: byte[] buffer = new byte[1024]; FileInputStream fis = new FileInputStream("path_to_file"). while((fis.read(buffer) != -1) // do something with

我有一个包含tcp数据包的字节文件。我想使用套接字读取这些数据包


那么,是否可以使用套接字在没有连接的情况下读取此文件?

否,但您可以使用FileInputStream并从文件中读取字节,如以下代码段所示:

byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream("path_to_file").

while((fis.read(buffer) != -1)
    // do something with the bytes readed
FileInputStream mInStream = new FileInputStream("file path").
byte[] buffer = new byte[1024]; 

    // Keep listening to the InputStream 
    while (true) {
        try {
         bytes = mInStream.read(buffer, 0, buffer.length);
        }catch {} 
    }