Tohedul
Tohedul

Reputation: 29

PDF file write issue - BluetoothSocket OutputStream.write()

I'm facing an issue writing PDF file to BluetoothSocket OutputStream in my android project. Text file write(print) is working fine but when I'm writing PDF file, it prints out some gibberish text not the data inside the PDF file. Here is my code snippet:

            File file = new File("/storage/emulated/0/Download/sample.pdf");

            inputStream = new FileInputStream(file);
            byte[] bytes = new byte[(int) file.length()];

            int nextByte;
            while ((nextByte = inputStream.read(bytes, 0, bytes.length)) != -1) {
                outputStream.write(bytes, 0, nextByte);
                outputStream.flush();
            }

            inputStream.close();
            outputStream.close();

Here outputStream is BluetoothSocket OutputStream.(ex: bluetoothSocket.getOutputStream())

Upvotes: 0

Views: 260

Answers (0)

Related Questions