Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class Main
- {
- public static void main(String[] args)
- {
- String testo;
- try
- {
- RandomAccessFile raf = new RandomAccessFile("C:\\Users\\Informatica\\Desktop\\vendite.bin", "rw");
- //GENERAZIONE FILE PER PROVARE
- /*
- for(int i = 0; i < 3; i++) {
- raf.writeUTF("AmazoNoCopyright");
- raf.writeInt(898);
- raf.writeDouble(10.4);
- raf.writeDouble(15.15);
- }
- raf.writeUTF("Med store");
- raf.writeInt(88);
- raf.writeDouble(115.4);
- raf.writeDouble(19.53);
- raf.writeUTF("Med store");
- raf.writeInt(74);
- raf.writeDouble(115.4);
- raf.writeDouble(19.53);
- raf.writeUTF("VenditaPcUsati");
- raf.writeInt(56);
- raf.writeDouble(16);
- raf.writeDouble(78);
- */
- //lettura file
- raf.seek(0);
- FileWriter fw = new FileWriter("C:\\Users\\Informatica\\Desktop\\vendite.csv");
- BufferedWriter scrivi = new BufferedWriter(fw);
- FileWriter fwh = new FileWriter("C:\\Users\\Informatica\\Desktop\\vendite.html");
- BufferedWriter html = new BufferedWriter(fwh);
- html.write("<!DOCTYPE html>\n" +
- "<html>\n" +
- "<head>\n" +
- " <meta charset='utf-8'>\n" +
- " <title>Apricot Computers</title>\n" +
- " <style>\n" +
- " td{border: 1px solid #000; spacing: 0px; padding: 0px;}\n" +
- " </style>\n" +
- "</head>\n" +
- "<body>\n" +
- " <table>\n" +
- " <tr>\n" +
- " <td>Num negozio</td> <td>Nome</td> <td>Vendite</td> <td>Prezzo</td> <td>sconto</td>\n" +
- " </tr>");
- String nam = "";
- int p = 1;
- for(int i = 0; i < 6; i++)
- {
- String name = raf.readUTF();
- int n = raf.readInt();
- double prezzo = raf.readDouble(), sconto = raf.readDouble();
- if (nam.equals(name))
- p++;
- else
- p = 1;
- nam = name;
- testo = p + "," + name + "," + n + "," + prezzo + "," + sconto + "\n";
- scrivi.write(testo);
- html.write("<tr>\n" +
- " <td>" + p + "</td> <td>" + name +"</td> <td>" + n + "</td> <td>" + prezzo + "</td> <td>" + sconto + "</td>\n" +
- " </tr>");
- }
- html.write(" </table>\n" +
- "</body>\n" +
- "</html>");
- raf.close();
- scrivi.close();
- fw.close();
- html.close();
- fwh.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement