Skip to content
Commits on Source (2)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>IO-ramzi</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.io.ramzi;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author ramzi
*/
public class IoObjet {
public static void main(String[] args) {
String toSave = "Message a enregistrer en binaire";
try (ObjectOutputStream oos
= new ObjectOutputStream(
new FileOutputStream(
"sortieBinaire.bin"))) {
oos.writeObject(toSave);
}
catch (FileNotFoundException e) {
Logger.getLogger(IoObjet.class.getName()).log(Level.SEVERE, null, e);
}
catch (IOException ex) {
Logger.getLogger(IoObjet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.io.ramzi;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Scanner;
/**
*
* @author ramzi
*/
public class IoTexte {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try (
BufferedWriter out = new BufferedWriter(
new FileWriter("test.txt")
)) {
System.out.println("Entrez une phrase à ajouter: ");
out.append(sc.nextLine());
out.flush();
out.close();
} catch (IOException e) {
//Logger.getLogger(IoTexte.class.getName()).log(Level.SEVERE, null, args);
}
try {
BufferedReader in = new BufferedReader(
new FileReader("test.txt", Charset.forName("utf-8"))
);
String ligne = in.readLine();
while (ligne != null) {
System.out.println(ligne);
ligne = in.readLine();
}
in.close();
} catch (FileNotFoundException e) {
//Logger.getLogger(IoTexte.class.getName()).log(Level.SEVERE, null, args);
} catch (IOException e) {
//Logger.getLogger(IoTexte.class.getName()).log(Level.SEVERE, null, args);
}
}
}
#Generated by Maven
#Tue Apr 04 10:29:37 CEST 2023
groupId=com.mycompany
artifactId=IO-ramzi
version=1.0-SNAPSHOT
com\mycompany\io\ramzi\IoObjet.class
com\mycompany\io\ramzi\IoTexte.class
C:\Users\ramzi\Desktop\LDNR\repertoires-java\IO-ramzi\src\main\java\com\mycompany\io\ramzi\IoObjet.java
C:\Users\ramzi\Desktop\LDNR\repertoires-java\IO-ramzi\src\main\java\com\mycompany\io\ramzi\IoTexte.java