System.out.println - redirecionar a saida para impressora

4 respostas
helder_pestana

Gostaria de enviar Strings para a impressora como faço isso utilizando System.out.println ?

Obrigado

4 Respostas

RRaminelli

Só passar a String:

public static void sendLPT1(final String str) {
                new Thread() {
                    public void run() {
                        try {
                            FileOutputStream os = new FileOutputStream("LPT1");
                            PrintStream ps = new PrintStream(os);
                            ps.print(str);
                            os.close();
                        } catch(Exception e) {
                        }
                    }
                }.start();
            }
cv1

Lembrando que abrir “LPT1” so funciona no Windows. No Linux, Mac e qualquer outro sistema operacional, a JVM vai rir da sua cara.

helder_pestana

e se nao for plataforma windows?

marciofermino

Eu fiz assim>

package Report;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.PrintStream;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class Report extends HttpServlet {

private static final long serialVersionUID = 1L;
public static void sendLPT1(final String str) {  
    new Thread() {  
        public void run() {  
            try {  
                FileOutputStream os = new FileOutputStream("LPT1");  
				PrintStream ps = new PrintStream(os);  
                ps.print(str);  
                os.close();  
            } catch(Exception e) {  
            }  
        }  
    }.start();  
}  
public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			
			sendLPT1((int) (Math.random() * 100) + "\t");
		}
		System.out.println("");
	}

}

}

Imprimiu certinho, agora só faltou um a quebra de linha
um #10#13 ???

Criado 2 de agosto de 2005
Ultima resposta 25 de jul. de 2012
Respostas 4
Participantes 4