diff --git a/.gitignore b/.gitignore index 0eb28e4..a0593c2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ # BlueJ files *.ctxt +# Created files +*.txt # Mobile Tools for Java (J2ME) .mtj.tmp/ diff --git a/fichier1.pdf b/fichier1.pdf new file mode 100644 index 0000000..8cc7d01 Binary files /dev/null and b/fichier1.pdf differ diff --git a/src/exercice6part2.java b/src/exercice6part2.java new file mode 100644 index 0000000..f9812f5 --- /dev/null +++ b/src/exercice6part2.java @@ -0,0 +1,35 @@ +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +import com.itextpdf.text.Document; +import com.itextpdf.text.DocumentException; +import com.itextpdf.text.Paragraph; +import com.itextpdf.text.pdf.PdfWriter; + +public class exercice6part2 { + public static void main(String[] args) { + // création du document + try { + // Propriétés du document + Document document = new Document(); + + // Ouverture d'un canal de sortie vers 'fichier1.pdf' + FileOutputStream fos = new FileOutputStream("fichier1.pdf"); + // Linkage entre le document et le fichier de sortie + PdfWriter.getInstance(document, fos); + // Un fois ouvert, on peut écrire dans le fichier pdf souhaité. + document.open(); + document.addAuthor("Yohan Boujon"); + document.addCreationDate(); + document.addTitle("premier document"); + document.add(new Paragraph("paragraphe 1")); + document.close(); + } catch (FileNotFoundException e) { + // Si le nom de FileOutputStream est nul. + e.printStackTrace(); + } catch (DocumentException de) { + // Erreur provenant de ItextPDF quelconque. + System.err.println(de.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/partie6/TestIO.java b/src/partie6/TestIO.java new file mode 100644 index 0000000..4ba4043 --- /dev/null +++ b/src/partie6/TestIO.java @@ -0,0 +1,18 @@ +package partie6; + +import java.io.FileWriter; +import java.io.IOException; + +public class TestIO { + public static void main(String[] args) throws IOException { + try { + FileWriter myFile = new FileWriter(""); + myFile.write("Super ligne dans mon fichier, waouw."); + myFile.close(); + } catch (IOException e) { + FileWriter logFile = new FileWriter("test_io.log"); + logFile.write(e.getMessage()); + logFile.close(); + } + } +} diff --git a/src/partie6/TestIO2.java b/src/partie6/TestIO2.java new file mode 100644 index 0000000..0658dc6 --- /dev/null +++ b/src/partie6/TestIO2.java @@ -0,0 +1,19 @@ +package partie6; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class TestIO2 { + public static void main(String[] args) { + System.out.println("Veuillez saisir votre nom:"); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String inputLine = reader.readLine(); + reader.close(); + System.out.println("Votre nom est " + inputLine); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/partie6/TestIO3.java b/src/partie6/TestIO3.java new file mode 100644 index 0000000..cd4e86e --- /dev/null +++ b/src/partie6/TestIO3.java @@ -0,0 +1,26 @@ +package partie6; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +public class TestIO3 { + public static void main(String[] args) throws IOException { + FileReader fileIn; + FileWriter fileOut; + // Copie le fichier a_lire.txt dans a_ecrire2.txt. + // Si le fichier n'existe pas renvoi une exception. + try { + fileIn = new FileReader("a_lire.txt"); + fileOut = new FileWriter("a_ecrire2.txt"); + int c; + while ((c = fileIn.read()) != -1) { + fileOut.write(c); + } + fileIn.close(); + fileOut.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +}