- 论坛徽章:
- 0
|
小弟最近研究 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 数据,但中文为乱码: |
|