1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| package test;
//Ceci importe la classe Scanner du package java.util
import java.awt.BorderLayout;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
//Ceci importe toutes les classes du package java.util
public class Test {
public static void main(String[] args) {
JFrame fenetre = new JFrame();
fenetre.setTitle("Programme Surveillance Parc Informatique");
fenetre.setSize(400, 1000);
fenetre.setLocationRelativeTo(null);
// Termine le processus lorsqu'on clique sur la croix rouge
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//ici on créé un panneau dans lequel on va pouvoir insérer des composants tels que JTextField
JPanel contentPane = new JPanel(new BorderLayout());
//on créé un composant qui accueillera le texte
JTextField champsTexte = new JTextField("");
//on insère le composant dans le panneau
contentPane.add(champsTexte);
//On insère le panneau dans la fenêtre
fenetre.setContentPane(contentPane);
// create file object
File file = new File("log_annexe.txt");
File file2 = new File("log_annexe.txt");
BufferedInputStream bin = null;
try {
// create FileInputStream object
FileInputStream fin = new FileInputStream(file);
FileInputStream fin2 = new FileInputStream(file2);
// create object of BufferedInputStream
bin = new BufferedInputStream(fin);
bin = new BufferedInputStream(fin2);
// create a byte array
byte[] contents = new byte[1024];
byte[] contents2 = new byte[1024];
int bytesRead = 0;
StringBuilder strSB = new StringBuilder();
while ((bytesRead = bin.read(contents)) != -1) {
strSB.append(new String(contents, 0, bytesRead));
// strFileContents = new String(contents, 0, bytesRead);
// strFileContents2 = new String(contents, 0, bytesRead);
System.out.print(strSB);
champsTexte.setText(strSB.toString());
}
} catch (FileNotFoundException e) {
System.out.println("File not found" + e);
} catch (IOException ioe) {
System.out.println("Exception while reading the file " + ioe);
} finally {
// close the BufferedInputStream using close method
try {
if (bin != null)
bin.close();
} catch (IOException ioe) {
System.out.println("Error while closing the stream :" + ioe);
}
}
// Et enfin, la rendre visible
fenetre.setVisible(true);
}
} |
Partager