Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在windows操作系统中使用打印机和在linux ubuntu中使用我的程序_Java_Printing_Epson - Fatal编程技术网

Java 如何在windows操作系统中使用打印机和在linux ubuntu中使用我的程序

Java 如何在windows操作系统中使用打印机和在linux ubuntu中使用我的程序,java,printing,epson,Java,Printing,Epson,服务器linux ubuntu中的我的程序和Windows中的我的打印机 我想从链接打印数据并在windows中打印 我尝试打印以下内容: SMB:\\\\Ip printer\\Name printer 但它不起作用 有解决办法吗 我的代码是: string1="test"; InputStream br = new ByteArrayInputStream(test.getBytes()); BufferedReader in = new BufferedReader(new InputS

服务器linux ubuntu中的我的程序和Windows中的我的打印机 我想从链接打印数据并在windows中打印 我尝试打印以下内容:

SMB:\\\\Ip printer\\Name printer
但它不起作用 有解决办法吗

我的代码是:

string1="test";
InputStream br = new ByteArrayInputStream(test.getBytes());
BufferedReader in = new BufferedReader(new InputStreamReader(br));
String line;
FileWriter out = new FileWriter("SMB:\\\\IP printer\\name printer");
while((line = in.readLine()) != null)
{  
    System.out.println("line"+line);
    out.write(line);
    out.write(0x0D);  CR
    out.write('\n');
    writer.println(line);
}
out.close();
in.close();
我的打印机是EPSON TM-U295

您应该使用

这就是Java为此类情况提供的API。 下面是一个小代码片段,让您开始学习:

PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable(new CustomPrintable("DATA TO PRINT"));
boolean printOK = printerJob.printDialog();
if (printOK){} 
    try {
        printerJob.print();
    }
    catch (PrinterException e){
        // Error
    }
}
我刚刚意识到我忘了提到如何连接打印机,这里有一个你应该使用的Usefoull

这就是Java为此类情况提供的API。 下面是一个小代码片段,让您开始学习:

PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable(new CustomPrintable("DATA TO PRINT"));
boolean printOK = printerJob.printDialog();
if (printOK){} 
    try {
        printerJob.print();
    }
    catch (PrinterException e){
        // Error
    }
}

我刚刚意识到我忘了提到如何连接打印机,下面是一个usefoul

感谢您的回答,在这里我给出了打印机的名称?
PrintService PrintService=PrintUtility.findPrintService(printerName)适用于我:)。检查我给你的链接。如果我的程序在linux上,打印机在windows上?什么在里面(printerName)?如果我使用linux,你需要映射打印机。在谷歌上搜索一下。谢谢你的回答,我在这里给出了打印机的名称?
PrintService PrintService=printputility.findPrintService(printerName)适用于我:)。检查我给你的链接。如果我的程序在linux上,打印机在windows上?什么在里面(printerName)?如果我使用linux,你需要映射打印机。用谷歌搜索一下。