Bonjour,

Je suis un développeur débutant, je dois écrire un programme qui permet d'écrire dans fichier caratere par caractere la chaine de caractere tapée au clavier. il faut noter que chaque caractere doit etre dans chaque ligne + Relatives Times stamp.

Example : Chaine de Caratere tapée par l'utilisateur : Bonjour

Fichier Correspondant contient :

1 B 17h31m01s
2 o 17h31m03s
3 n etc
4 j
5 o
6 u
7 r

PS: La boucle for (ainsi que la boucle While) ne fonctionne pas dans la fonction ecrire fichier

Voici mon programme : Profile.java

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
85
86
87
88
89
 
import java.io.*;
 
public class Profile
{
public static String lireString()
{
String ligne_lue=null;
try
{
InputStreamReader lecteur=new InputStreamReader(System.in);
BufferedReader entree=new BufferedReader(lecteur);
ligne_lue=entree.readLine();
}
catch(IOException err)
{
System.exit(0);
}
return ligne_lue;
}
 
 
 
public static void ecrireFichier(String path, String text)
{
PrintWriter ecri ;
try
{
ecri = new PrintWriter(new FileWriter(path));
 
for (int i=1; i<text.length; i++)
{
String letter = text.substring(0, i);
ecri.println(letter);
text = text.substring(i+1);
}
 
 
ecri.flush();
ecri.close();
}
catch (NullPointerException a)
{
System.out.println("Erreur : pointeur null");
}
catch (IOException a)
{
System.out.println("Problème d'IO");
}
}
 
public String lireFichier (String path)
{
BufferedReader lect ;
String tmp = "";
try
{
lect = new BufferedReader(new FileReader(path)) ;
while (lect.ready()==true)
{
tmp += lect.readLine() ;
}//while
}//try
catch (NullPointerException a)
{
System.out.println("Erreur : pointeur null");
}
catch (IOException a)
{
System.out.println("Problème d'IO");
}
return tmp;
}
 
 
 
public static void main (String[] args)
{
 
String ch="";
System.out.println("Entrer un Input:");
ch=Profile.lireString();
System.out.println("Input: " + ch);
ecrireFichier ("example.txt", ch);
 
}
 
 
}