danimo
1050Messages postés
15 janvier 2006Date d'inscription
30 mai 2012Dernière intervention
19 août 2008 à 17:28
Salut,
Fais (si tu veux) un essai avec ce code, je n'ai pas de fichiers .ods et .odt pour le faire.
import java.io.*;
class LireLignesFichier
{
static String fic = "";
// les lignes en // qui suivent me m'evitent, pour mes tests, d'entrer le nom du fichier
// Je procede par copie (Ctrl + c) de l'un des noms et, a la demande d'intro le colle (Ctrl + v)
// static String fic = "TabTextListesJ2sev142.txt";
// static String fic = "LireLignesFichier.java";
// static String fic = "LireLignesFichier.class";
// static String fic = "LireLignesFichier";
// static String fic = "LireLignesFichierX.java"; // fichier inexistant
// static String fic = "DateCalendar.java";
// static String fic = "FirstApplet.html";
static String extension = "";
static InputStream is = null;
static InputStreamReader isr = null;
static BufferedReader br = null;
static BufferedReader clavier = null;
static String ligne;
static String lignepartielle;
static int ctr = 0;
static int ctrlignes = 0;
static int lgline = 0;
public static void main(String[] argv) throws IOException
{
int ind = 0;
do
{
fic = "";
try
{
fic = (String)javax.swing.JOptionPane.showInputDialog
(null,
"Entrez le nom du fichier (avec son extension)\n" // message
+ "OU rien pour sortir",
"Saisir un nom de fichier", // titre
javax.swing.JOptionPane.PLAIN_MESSAGE, // type message
null, // icone
null,
"LireLignesFichier.java"); // Nom par defaut
}
catch (NullPointerException npe)
{
System.out.println(npe.toString());
javax.swing.JOptionPane.showMessageDialog(null, "Le texte entré est\n" + fic);
fic = "";
}
if (fic.equals(""))
return;
ind = fic.lastIndexOf(".");
if (ind == -1)
javax.swing.JOptionPane.showMessageDialog
(null,"Pas d'extension, Recommencer !");
}
while(ind == -1);
extension = fic.substring(ind);
String titre = "Liste d'un fichier" + extension;
do
{
try
{
is = new FileInputStream(fic);
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
String ligne;
while ((ligne = br.readLine())!= null)
{ System.out.println("________________________________________"
+ "________________________________________");
javax.swing.JOptionPane.showMessageDialog(null,mess + "\n\n"
+ "... et fin.");
javax.swing.JOptionPane.showMessageDialog
(null,"Consulter éventuellement la console.");
br.close();
}
//catch (FileNotFoundException fnfe)
catch (IOException ioe)
{
System.out.println(ioe.toString());
javax.swing.JOptionPane.showMessageDialog(null," Fichier "
+ fic + " non trouve");
}
catch (RuntimeException re)
{
System.out.println(re.toString());
javax.swing.JOptionPane.showMessageDialog(null,"Voir la console");
}
fic = (String)javax.swing.JOptionPane.showInputDialog
(null, "Entrez un autre nom de fichier (avec son extension)\n"
+ "OU rien pour sortir");
}
while (!fic.equals(""));
return;
}
}
C'est un extrait, j'espere qu'il ne manque rien pour l'essai.
Tiens moi au courant...
Cordialement.
Dan