我这里有个程序是要把一个字符串打印出来,但是在打印的时候当字符串是字母开始后面接着数字(例:ZH0707081122),并且超过9位的时候程序没有出错但是打印机会报不支持你的打印格式的错误,但是如果把数字放在前面字母放在后面,或者小于9位就没有出错打印出来的。当然纯字符纯数字也没有出错。代码如下:
lotid = "CSJMAT001111";
byte[] bais = lotid1.getBytes();
DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.AUTOSENSE;
SimpleDoc myDoc = new SimpleDoc(bais, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
try {
job.print(myDoc, aset);
}catch (Exception e) {
throw e;
}
另外,我看了一下我这里的打印机只支持BYTE_ARRAY和INPUT_STREAM这两种DocFlavor
INPUT_STREAM我用了ByteArrayInputStream也不行。希望个位大虾指点一下错误或者有没有其他的解决方法。
lotid = "CSJMAT001111";
byte[] bais = lotid1.getBytes();
DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.AUTOSENSE;
SimpleDoc myDoc = new SimpleDoc(bais, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
try {
job.print(myDoc, aset);
}catch (Exception e) {
throw e;
}
另外,我看了一下我这里的打印机只支持BYTE_ARRAY和INPUT_STREAM这两种DocFlavor
INPUT_STREAM我用了ByteArrayInputStream也不行。希望个位大虾指点一下错误或者有没有其他的解决方法。
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String lotid = "CSJMAT001111 ";
System.out.println(lotid.toString()); }
}LZ 你要做什么? 不就是打印字符串吗,你的代码我看不下去。