0

我在我的 android 项目中将PDF 文件写入 BluetoothSocket OutputStream时遇到问题。文本文件写入(打印)工作正常,但是当我编写 PDF 文件时,它会打印出一些乱码,而不是 PDF 文件中的数据。这是我的代码片段:

            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();

这里的outputStream是 BluetoothSocket OutputStream。(例如:bluetoothSocket.getOutputStream())

4

0 回答 0