[请教]通过JAVA读取AS400 SPOOL FILE后,如何将SPOOL FILE内容存到本地
(2011-12-23 00:34:08)
标签:
java
如何
杂谈
[请教]通过JAVA读取AS400 SPOOL FILE后,如何将SPOOL
FILE内容存到本地非常感谢各位的回复,谢谢!
现在通过JAVA连AS400已经没有问题.不过还有一点小疑问:
try
{
System.out.println("System connected
begin...");
as400.connectService(AS400.COMMAND);
System.out.println("System connected
success...");
SpooledFileList splflist = new SpooledFileList(as400);
splflist.openSynchronously();
splflist.setUserFilter("dx001");
Enumeration enu = splflist.getObjects();
int i = 0;
while(enu.hasMoreElements())
{
i++;
SpooledFile splf = (SpooledFile)enu.nextElement();
System.out.println("I=" + i +
": " + splf.getJobName() +
"_" + splf.getJobNumber() +
"_" + splf.getJobUser());
byte[] buf = new byte;
int bytesRead;
//AS400 sys = new AS400();
// SpooledFile splf = new SpooledFile( sys, // AS400
// "MICR", // splf name
// 17, // splf number
// "QPRTJOB", // job name
// "QUSER", // job user
// "020791" ); // job
number
// open the spooled file for reading and get the input stream
to
// read from it.
InputStream in = splf.getInputStream();
File file = new File("C:\\" +
splf.getJobName()+"_"+splf.getJobNumber()+".txt");
RandomAccessFile raf = null;
raf = new RandomAccessFile(file,
"rw");
do
{
// read up to buf.length bytes of raw spool data into
// our buffer.The actual bytes read will be returned.
// The data will be a binary printer data stream that is the
// contents of the spooled file.
bytesRead = in.read( buf );
if( bytesRead != -1 )
{
// process the spooled file data.
System.out.println( "Read " +
bytesRead + " bytes" );
raf.write(buf);
for(int j = 0; j < buf.length; j++)
{
System.out.print(buf);
}
}
} while( bytesRead != -1 );
System.out.println(buf.toString());
in.close();
raf.close();
//String str_buf=new
String(CharConverter.byteArrayToString(sys));//此处转换编码
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
System.out.println("System connected
fail...");
System.exit(0);
}
在读到到一个SPOOL FILE后,我想把它写到本地http://www.dmtucao.com的步步高学习机TEXT文件中,我是将BYTE[]方式读取SPOOL
FILE的,然后写到本地的TEXT文件中,但是全部都是乱码,请教应该怎么样改呢?
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。