-1

I have a byte file that contains tcp packets. I want to use sockets to read those packets.

so is it possible to use Sockets to read this file without connection ?

nhb.sajol
  • 37
  • 8
MBH
  • 16,271
  • 19
  • 99
  • 149

2 Answers2

2
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 {} 
    }
Vid
  • 1,012
  • 1
  • 14
  • 29
1

No, but you can use a FileInputStream and read bytes from the files like the following snippet:

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

while((fis.read(buffer) != -1)
    // do something with the bytes readed
Kennedy Oliveira
  • 2,141
  • 2
  • 20
  • 25