如何在codenameone中显示字节数组(byte [])作为文件(pdf / doc)?

时间:2018-02-13 12:52:58

标签: arrays codenameone

我从服务中得到字节数组(byte [])的响应。在我的应用程序中,我想在应用程序本身中显示文件(pdf / doc)。可能吗?有没有办法以codenameone保存和查看文件?

1 个答案:

答案 0 :(得分:1)

请尝试此代码

String newString = String(byte[] bytes);

对于PDF,您需要创建一个文件并使用本机查看器打开它:

FileSystemStorage fs = FileSystemStorage.getInstance();
String fileName = fs.getAppHomePath() + "myPDF.pdf";
try(OutputStream os = fs.openOutputStream(fileName)) {
    os.write(myByteArrayData);
}
Display.getInstance().execute(fileName);
相关问题