Scholieren.com forum

Scholieren.com forum (https://forum.scholieren.com/index.php)
-   Huiswerkvragen: Exacte vakken (https://forum.scholieren.com/forumdisplay.php?f=17)
-   -   [IN] Java programma zoeken in een ander .txt bestand (https://forum.scholieren.com/showthread.php?t=1815674)

Lund 28-09-2010 13:51

Java programma zoeken in een ander .txt bestand
 
Hallo allemaal,

Ik ben op dit moment bezig om een programma te schrijven, wat een file krijgt ingelezen. Hieronder file1.

File1

>Jan
>Ilona

File 2

>Jan Leeftijd=31 Cijfer=8
Wiskunde
>Klaas Leeftijd=60 Cijfer=6
Wiskunde
Scheikunde
>Ilona Leeftijd=23 Cijfer=10
Biologie
Scheikunde
Gym

Wat ik wil is een output file (nieuw .txt file) waarin staat:

>Jan Leeftijd=31 Cijfer=8
Wiskunde
>Ilona Leeftijd=23 Cijfer=10
Biologie
Scheikunde
Gym

Op dit moment kan ik file1 inlezen, en kan ik dus in file1 de namen kan zien. Maar hoe kan ik de rest het beste aanpakken?

Code:


import java.util.Scanner;
import javax.swing.JFileChooser;

public class NameFinder {
        public static void main(String [] args) throws Exception {
                JFileChooser fileChooser = new JFileChooser();
                if (fileChooser.showOpenDialog(null)
                        == JFileChooser.APPROVE_OPTION ) {

                                // Get the selected file.
                                java.io.File file = fileChooser.getSelectedFile();

                                // Create Scanner for the file.
                                Scanner input = new Scanner(file);

                                // Read text from the file.
                                // Query1 = Eerste woord in de regel.
                                while (input.hasNext()) {
                                        String Query1 = input.next();
                                        System.out.println(Query1);
                                        //System.out.println(input.nextLine());
                                }

                                // Close the file.
                                input.close();
                        }
                        else {
                                System.out.println("No file selected");
                        }
                }
        }



Alle tijden zijn GMT +1. Het is nu 02:58.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.