-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
  • 15,677
  • 19
  • 96
  • 145

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
  • 992
  • 1
  • 11
  • 28
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
  • 1,971
  • 2
  • 16
  • 25