【发布时间】:2015-10-19 12:07:34
【问题描述】:
我有一个包含 tcp 数据包的字节文件。我想使用套接字来读取这些数据包。
那么是否可以使用 Sockets 在不连接的情况下读取此文件?
【问题讨论】:
我有一个包含 tcp 数据包的字节文件。我想使用套接字来读取这些数据包。
那么是否可以使用 Sockets 在不连接的情况下读取此文件?
【问题讨论】:
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 {}
}
【讨论】:
不,但您可以使用 FileInputStream 并从文件中读取字节,如下面的 sn-p:
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream("path_to_file").
while((fis.read(buffer) != -1)
// do something with the bytes readed
【讨论】: