Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Main
  4. {
  5. public static void main(String[] args)
  6. {
  7. String testo;
  8. try
  9. {
  10. RandomAccessFile raf = new RandomAccessFile("C:\\Users\\Informatica\\Desktop\\vendite.bin", "rw");
  11.  
  12.  
  13. //GENERAZIONE FILE PER PROVARE
  14. /*
  15. for(int i = 0; i < 3; i++) {
  16. raf.writeUTF("AmazoNoCopyright");
  17. raf.writeInt(898);
  18. raf.writeDouble(10.4);
  19. raf.writeDouble(15.15);
  20. }
  21. raf.writeUTF("Med store");
  22. raf.writeInt(88);
  23. raf.writeDouble(115.4);
  24. raf.writeDouble(19.53);
  25. raf.writeUTF("Med store");
  26. raf.writeInt(74);
  27. raf.writeDouble(115.4);
  28. raf.writeDouble(19.53);
  29. raf.writeUTF("VenditaPcUsati");
  30. raf.writeInt(56);
  31. raf.writeDouble(16);
  32. raf.writeDouble(78);
  33. */
  34.  
  35. //lettura file
  36. raf.seek(0);
  37.  
  38. FileWriter fw = new FileWriter("C:\\Users\\Informatica\\Desktop\\vendite.csv");
  39. BufferedWriter scrivi = new BufferedWriter(fw);
  40.  
  41. FileWriter fwh = new FileWriter("C:\\Users\\Informatica\\Desktop\\vendite.html");
  42. BufferedWriter html = new BufferedWriter(fwh);
  43.  
  44. html.write("<!DOCTYPE html>\n" +
  45. "<html>\n" +
  46. "<head>\n" +
  47. " <meta charset='utf-8'>\n" +
  48. " <title>Apricot Computers</title>\n" +
  49. " <style>\n" +
  50. " td{border: 1px solid #000; spacing: 0px; padding: 0px;}\n" +
  51. " </style>\n" +
  52. "</head>\n" +
  53. "<body>\n" +
  54. " <table>\n" +
  55. " <tr>\n" +
  56. " <td>Num negozio</td> <td>Nome</td> <td>Vendite</td> <td>Prezzo</td> <td>sconto</td>\n" +
  57. " </tr>");
  58.  
  59. String nam = "";
  60. int p = 1;
  61. for(int i = 0; i < 6; i++)
  62. {
  63.  
  64. String name = raf.readUTF();
  65. int n = raf.readInt();
  66. double prezzo = raf.readDouble(), sconto = raf.readDouble();
  67.  
  68. if (nam.equals(name))
  69. p++;
  70. else
  71. p = 1;
  72.  
  73. nam = name;
  74. testo = p + "," + name + "," + n + "," + prezzo + "," + sconto + "\n";
  75. scrivi.write(testo);
  76. html.write("<tr>\n" +
  77. " <td>" + p + "</td> <td>" + name +"</td> <td>" + n + "</td> <td>" + prezzo + "</td> <td>" + sconto + "</td>\n" +
  78. " </tr>");
  79. }
  80.  
  81. html.write(" </table>\n" +
  82. "</body>\n" +
  83. "</html>");
  84. raf.close();
  85. scrivi.close();
  86. fw.close();
  87. html.close();
  88. fwh.close();
  89. } catch (FileNotFoundException e) {
  90. e.printStackTrace();
  91. } catch (IOException e) {
  92. e.printStackTrace();
  93. }
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement