免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2728 | 回复: 0
打印 上一主题 下一主题

用Java 取 400上Spool file 文件中文乱码问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-14 23:44 |只看该作者 |倒序浏览
小弟最近研究 IBM Tool Box 需要从AS/400 下载 spool File 文件,查阅资料后,下载已不成问题,但下载后,中文显示为乱码!求达人帮忙解决一下
代码如下:
try{
                        byte[] buf = new byte[32767];
                        PrintParameterList prtParm = new PrintParameterList();
                        prtParm.setParameter(PrintObject.ATTR_MFGTYPE,"*WSCST" );
                        prtParm.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT,"/QSYS.LIB/QWPDEFAULT.WSCST");

                        StringBuffer sbuf = new StringBuffer();
                        int bytesRead = 0;
                        AS400 as400 = new AS400("22.5.228.2","DEFAULT","DEFAULT");
                        System.out.println("connection success!");
                        SpooledFile splf = new SpooledFile(as400,        //AS400
                                        "SCS0043H",                                                        //splf name
                                        1,                                                                  //splf number
                                        "SC2UNWRTR",                                                //job name
                                        "SCUNWOPR",                                                        //job user
                                        "634512");                                                        //job number
                        //open the spooled file for reading and get the input stream ot read from it
                        PrintObjectTransformedInputStream in = null;
                        //PrintObjectInputStream ins = null;
                        in = splf.getTransformedInputStream(prtParm);
                        AS400BidiTransform abt;
                        abt = new AS400BidiTransform(424);
                        String dst = abt.toAS400Layout("some bidirectional string");
                        System.out.println("dst="+dst);
                        //SpooledFileOutputStream sfos = splf.
                        //ins = splf.getInputStream();
                        //System.out.println("GIF");
                        //InputStream in = splf.getInputStream(null);
                        do{
                                bytesRead = in.read( buf );
                                if( bytesRead != -1 ) { // process the spooled file data.
                                        sbuf.append(new String(buf,1,bytesRead));
                                }
                        }while (bytesRead!=-1);
                        File file = new File("C:/test1.txt");
                        java.io.FileWriter filew = new java.io.FileWriter(file);
                        filew.write(sbuf.toString());
                        filew.flush();
                        filew.close();
                       
                        in.close();
                        String output = sbuf.toString();
                        //String str_buf = new String(CharConverter.byteArrayToString(as400, sbuf.toString().getBytes()));
                        //System.out.println("output="+output);
                        //System.out.println(str_buf);
                        //System.out.println("output="+output);
                        System.out.print("lk="+new String(output.getBytes(),"GBK"));
                        //System.exit(0);
                }catch(Exception e)
                {
                        e.printStackTrace();
                }
已从400 以 ASCII码下载了Spool 数据,但中文为乱码:
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP