Exercice 6. Partie 4.
This commit is contained in:
parent
5a8b007fbd
commit
9bc78a2071
6 changed files with 100 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,6 +7,8 @@
|
|||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Created files
|
||||
*.txt
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
|
|
BIN
fichier1.pdf
Normal file
BIN
fichier1.pdf
Normal file
Binary file not shown.
35
src/exercice6part2.java
Normal file
35
src/exercice6part2.java
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
18
src/partie6/TestIO.java
Normal file
18
src/partie6/TestIO.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
19
src/partie6/TestIO2.java
Normal file
19
src/partie6/TestIO2.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
26
src/partie6/TestIO3.java
Normal file
26
src/partie6/TestIO3.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue