IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Lire un fichier texte en Java


Sujet :

avec Java

  1. #1
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut Lire un fichier texte en Java
    je veux récupérer les donnée qui sont sur un fichier .txt
    la forme de mon fichier est la suivante:

    2674.2
    une seule ligne qui contient de poids

  2. #2
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 565
    Points
    4 565
    Par défaut
    Quelle est la question?

  3. #3
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    Bonjour,

    la question comment je peux récupérer cette valeur et la mettre dans mon programme java .

    je veuxla mettre de le TextField poids
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    import java.util.Locale;
    import java.sql.*;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
     
     
     
    class FenText extends JFrame implements ActionListener 
    {
    	private double prixT;
    	private JButton tomate,carotte,chouxfleur,brocoli,courgette,haricot,poivron,pommedeterre,oignon,ail,poire,pomme,orange,citron,annanas,raisin,banane,kiwi,peche,fraise,balance,annuler;
    	private JPanel pan;
    	private JTextField poids ;
    	private JTextField prix  ;
    	private JTextField prixkg  ;
     
        public FenText()
        {
     
    	setSize(820, 720);//Définit sa taille : 680 pixels de large et 680 pixels de haut
    	setTitle("Legumes & Freuits BIO chez Abderraouf CHEBBAH ");//Définit un titre pour notre fenêtre
    	setResizable(false);//pour la résolution de la fenetre ne sera pas modifiable 
    	setLocationRelativeTo(null);//Pour mettre la fenetre au mileu d'ecran
    	setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);////Termine le processus lorsqu'on clique sur la croix rouge
     
    	pan = new JPanel();//creer un nouvelle panel
    	prixkg  = new JTextField();
    	prixkg.setEditable(false);
    	prixkg.setPreferredSize(new Dimension(180,50));
    	pan.add(new JLabel ("PRIX KG (€)"));
    	pan.add(prixkg);
    	poids = new JTextField();
    	poids.setEditable(false);
    	poids.setPreferredSize(new Dimension(180,50));
    	pan.add(new JLabel("POIDS (g)"));
    	pan.add(poids);
    	prix  = new JTextField();
    	prix.setEditable(false);
    	prix.setPreferredSize(new Dimension(180,50));
    	pan.add(new JLabel ("PRIX (€)"));
    	pan.add(prix);
     
     
    	/************************ajouter des photo pour les bouttons *****************************/	
    	ImageIcon AnanasImage = new ImageIcon("ananas.png");
    	ImageIcon CitronImage = new ImageIcon("citron.png");
    	ImageIcon PommeImage = new ImageIcon("pomme.png");
    	ImageIcon BananeImage = new ImageIcon("banane.png");
    	ImageIcon RaisinImage = new ImageIcon("raisin.png");
    	ImageIcon KiwiImage = new ImageIcon("kiwi.png");
    	ImageIcon PoireImage = new ImageIcon("poire.png");
    	ImageIcon FraiseImage = new ImageIcon("fraise.png");
    	ImageIcon PecheImage = new ImageIcon("peche.png");
    	ImageIcon OrangeImage = new ImageIcon("orange1.png");
    	ImageIcon CourgetteImage = new ImageIcon("cougette.png");
    	ImageIcon AilImage = new ImageIcon("ail.png");
    	ImageIcon oignonImage = new ImageIcon("oignon.png");
    	ImageIcon HaricotImage = new ImageIcon("haricot.png");
    	ImageIcon BrocoliImage = new ImageIcon("brocoli.png");
    	ImageIcon PmmedeterreImage = new ImageIcon("pommedeterre.png");
    	ImageIcon TomateImage = new ImageIcon("tomate.png");
    	ImageIcon PoivrontImage = new ImageIcon("poivron.png");
    	ImageIcon CarotteiImage = new ImageIcon("carotte.png");
    	ImageIcon ChouxfleurImage = new ImageIcon("chouxfleur.png");
    	ImageIcon BlanceImage = new ImageIcon("balance.png");
    	ImageIcon AnnulerImage = new ImageIcon("annuler.png");
     
     
    	/**************Création des nouveux bouttons et metttre les imange dedans*****************/
    	carotte =new JButton("<html>CAROTTE BIO <br><br><br><br><br>1.50€/Kg</html>",CarotteiImage);
    	tomate =new JButton("<html>TOMATE BIO <br><br><br><br><br>1.50€/Kg</html>",TomateImage);
    	pommedeterre =new JButton("<html><br>POMME DE TERRE BIO <br><br><br>1.50€/Kg</html>",PmmedeterreImage);
    	poivron =new JButton("<html>POIVRON BIO <br><br><br><br><br>1.60€/Kg</html>",PoivrontImage);
    	courgette =new JButton("<html>COURGETTE BIO <br><br><br><br>1.10€/Kg</html>",CourgetteImage);
    	oignon =new JButton("<html>OIGNON BIO <br><br><br><br><br>1.50€/Kg</html>",oignonImage);
    	ail =new JButton("<html>AIL BIO <br><br><br><br><br>1.50€/Kg</html>",AilImage);
    	brocoli =new JButton("<html>BROCOLI BIO <br><br><br><br><br>1.80€/Kg</html>",BrocoliImage);
    	haricot =new JButton("<html>HARICOT BIO <br><br><br><br><br>1.40€/Kg</html>",HaricotImage);
    	chouxfleur =new JButton("<html>CHOUXFLEUR BIO <br><br><br><br>2.20€/Kg</html>",ChouxfleurImage);
    	kiwi =new JButton("<html>KIWI BIO <br><br><br><br>4.30€/Kg</html>",KiwiImage);
    	poire =new JButton("<html>POIRE BIO <br><br><br><br><br>1.50€/Kg</html>",PoireImage);
    	citron =new JButton("<html>CITRON BIO <br><br><br><br><br>1.50€/Kg</html>",CitronImage);
    	banane =new JButton("<html>BANANE BIO <br><br><br><br>1.99€/Kg</html>",BananeImage);
    	fraise =new JButton("<html>FRAISE BIO <br><br><br><br>2.90€/Kg</html>",FraiseImage);
    	peche =new JButton("<html>PECHE BIO <br><br><br><br>2.70€/Kg</html>",PecheImage);
    	annanas =new JButton("<html>ANNANAS BIO <br><br><br><br><br>1.50€/Kg</html>",AnanasImage);
    	raisin =new JButton("<html>RAISIN BIO <br><br><br><br><br>1.50€/Kg</html>",RaisinImage);
    	orange =new JButton("<html>ORANGE BIO <br><br><br><br>2.50€/Kg</html>",OrangeImage);
    	pomme =new JButton("<html>POMME BIO <br><br><br><br>3.00€/Kg</html>",PommeImage);
    	annuler =new JButton("<html>Annuler</html>",AnnulerImage);
    	balance =new JButton("<html> Payer </html>",BlanceImage);
    	pomme.addActionListener(this);
    	/************************mettre les dimension des buttons *****************************/
    	carotte.setPreferredSize(new Dimension(185, 110)); //mettre le dimention du button 
    	poivron.setPreferredSize(new Dimension(185, 110));
    	courgette.setPreferredSize(new Dimension(185, 110));
    	brocoli.setPreferredSize(new Dimension(185, 110));
    	haricot.setPreferredSize(new Dimension(185, 110));
    	pommedeterre.setPreferredSize(new Dimension(185, 110));
    	oignon.setPreferredSize(new Dimension(185, 110));
    	ail.setPreferredSize(new Dimension(185, 110));
    	tomate.setPreferredSize(new Dimension(185, 110));
    	chouxfleur.setPreferredSize(new Dimension(185, 110));
    	kiwi.setPreferredSize(new Dimension(185, 110));
    	banane.setPreferredSize(new Dimension(185, 110));
    	fraise.setPreferredSize(new Dimension(185, 110));
    	peche.setPreferredSize(new Dimension(185, 110));
    	poire.setPreferredSize(new Dimension(185, 110));
    	raisin.setPreferredSize(new Dimension(185, 110));
    	annanas.setPreferredSize(new Dimension(185, 110));
    	citron.setPreferredSize(new Dimension(185, 110));
    	orange.setPreferredSize(new Dimension(185, 110));
    	pomme.setPreferredSize(new Dimension(185, 110));
    	/************************Ajouter les buttons dans le panel*****************************/
    	pan.add(haricot);
    	pan.add(pommedeterre);           
    	pan.add(oignon);
    	pan.add(ail);
    	pan.add(tomate);
    	pan.add(courgette);           
    	pan.add(poivron);
    	pan.add(chouxfleur);
    	pan.add(brocoli);
    	pan.add(carotte);
    	pan.add(banane);
    	pan.add(poire);
    	pan.add(annanas);
    	pan.add(citron);
    	pan.add(raisin);
    	pan.add(fraise);
    	pan.add(orange);
    	pan.add(peche);
    	pan.add(pomme);
    	pan.add(kiwi);
    	pan.add(balance);
    	pan.add(annuler);
    	setContentPane(pan); 
    	/************************ activer la fonction des buttons *****************************/
    	haricot.addActionListener(this); 
    	annuler.addActionListener(this);
    	pommedeterre.addActionListener(this);
    	oignon.addActionListener(this);
    	ail.addActionListener(this);
    	tomate.addActionListener(this);
    	courgette.addActionListener(this);
    	poivron.addActionListener(this);
    	chouxfleur.addActionListener(this);
    	brocoli.addActionListener(this);
    	carotte.addActionListener(this);
    	banane.addActionListener(this);
    	poire.addActionListener(this);
    	annanas.addActionListener(this);
    	citron.addActionListener(this);
    	raisin.addActionListener(this);
    	fraise.addActionListener(this);
    	orange.addActionListener(this);
    	peche.addActionListener(this);
    	pomme.addActionListener(this);
    	kiwi.addActionListener(this);
    	balance.addActionListener(this);
    }
     
    public void clear()
    	{
    	prixkg.setText("   ");
    	prix.setText("   ");
    	poids.setText("   ");
    	}
     
     
     
     
     
     
     
     
    public void actionPerformed (ActionEvent e) //throws IOException pas possible
    {
     
     
    	if (e.getSource() == haricot) //donner une action a ce button 
    		{
    		prixkg.setText("1.40");
     
    		}
    	if (e.getSource() == annuler)
    		{
    		clear();
    		}
    	if (e.getSource() == pommedeterre)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == oignon)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == ail)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == tomate)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == courgette)
    		{
    		prixkg.setText("1.10");
    		}
    	if (e.getSource() == poivron)
    		{
    		prixkg.setText("1.60");
    		}
    	if (e.getSource() == chouxfleur)
    		{
    		prixkg.setText("2.20");
    		}
    	if (e.getSource() == brocoli)
    		{
    		prixkg.setText("1.80");
    		}
    	if (e.getSource() == carotte)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == banane)
    		{
    		prixkg.setText("1.99");
    		}
    	if (e.getSource() == poire)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == annanas)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == citron)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == raisin)
    		{
    		prixkg.setText("1.50");
    		}
    	if (e.getSource() == fraise)
    		{
    		prixkg.setText("2.90");
    		}
    	if (e.getSource() == orange)
    		{
    		prixkg.setText("2.50");
    		}
    	if (e.getSource() == peche)
    		{
    		prixkg.setText("2.70");
    		}
    	if (e.getSource() == pomme)
    		{
    		prixkg.setText("3.00");
    		}
    	if (e.getSource() == kiwi)
    		{
    		prixkg.setText("4.30");
    		}
     
    }
     
    }
     
    public class FenetreLegum3
    {
            public static void main (String args[])
            {
            FenText fen = new FenText();
            fen.setVisible(true);
     
        	}
    }
    Merci

  4. #4
    Expert confirmé Avatar de yildiz-online
    Homme Profil pro
    Architecte de domaine
    Inscrit en
    Octobre 2011
    Messages
    1 444
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Architecte de domaine

    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 444
    Points : 4 565
    Points
    4 565
    Par défaut
    Tu dois commencer par lire le fichier ligne par ligne, puis pour chaque ligne, rechercher si la valeur que tu cherches s'y trouve.

  5. #5
    Candidat au Club
    Homme Profil pro
    étudiant
    Inscrit en
    Janvier 2019
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : étudiant

    Informations forums :
    Inscription : Janvier 2019
    Messages : 7
    Points : 3
    Points
    3
    Par défaut
    enfait y a qu'une seule ligne et j'arrive par a la lire

  6. #6
    Modérateur

    Avatar de Robin56
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juin 2009
    Messages
    5 297
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Juin 2009
    Messages : 5 297
    Points : 13 670
    Points
    13 670
    Par défaut
    Bonjour,

    Fais un tour sur la FAQ qui te donnera ce qu'il faut pour y arriver : https://java.developpez.com/faq/java...igne-par-ligne

Discussions similaires

  1. Lire un fichier texte en Java
    Par inesmaya dans le forum Entrée/Sortie
    Réponses: 10
    Dernier message: 01/04/2015, 17h57
  2. Lire un fichier texte en Java
    Par azedine.web dans le forum EDI et Outils pour Java
    Réponses: 3
    Dernier message: 30/06/2014, 15h18
  3. Lire des ints dans un fichier texte avec java.io
    Par Vcouprie dans le forum Général Java
    Réponses: 1
    Dernier message: 07/02/2013, 20h01
  4. Lire un fichier Text en JAVA
    Par msahmi dans le forum Entrée/Sortie
    Réponses: 5
    Dernier message: 10/06/2009, 08h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo