Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. private void imprimir(String frase) {
  2. //Gera o arquivo de desconto
  3. try {
  4. File arquivo = new File("teste.txt");
  5. if (arquivo.exists()) {
  6. //se existir
  7. FileWriter arquivoTxt = new FileWriter(arquivo, true);
  8. PrintWriter linhasTxt = new PrintWriter(arquivoTxt);
  9. //ACREDITO QUE SO PODE TER 42 CARACTERES
  10. linhasTxt.println("==========================================");
  11. linhasTxt.println(" Thiosti Restaurante ");
  12. linhasTxt.println("===========================================");
  13. linhasTxt.println("********** NAO E DOCUMENTO FISCAL *********");
  14. linhasTxt.println("===========================================");
  15. linhasTxt.println("============= CUPOM DE DESCONTO ============");
  16. linhasTxt.println("===========================================");
  17. linhasTxt.println(frase);
  18. linhasTxt.println("===========================================");
  19. linhasTxt.println(" Agradecemos a preferencia! ");
  20. linhasTxt.println("Delivery - 3095-3838");
  21. //emiteComanda();
  22. } else {
  23. //se não existir
  24. arquivo.createNewFile();
  25. //criaTxt();
  26. }
  27. } catch (IOException error) {
  28. System.out.println("nao encontrei arquivo");
  29. }
  30.  
  31. try {
  32. java.io.InputStream is = new FileInputStream("teste.txt");
  33. Scanner sc = new Scanner(is);
  34. FileOutputStream fs = new FileOutputStream("Bematech_COM3:");
  35. PrintStream ps = new PrintStream(fs);
  36. while (sc.hasNextLine()) {
  37. String linhas = sc.nextLine();
  38. ps.println(linhas);
  39. }
  40. fs.close();
  41. } catch (IOException ex) {
  42. ex.printStackTrace();
  43. JOptionPane.showMessageDialog(null, "Erro encontrado ao imprimir comanda." + ex.toString());
  44. }
  45. }
Add Comment
Please, Sign In to add comment