Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Java vstup

Je to blbé no, trochu vlastní invence by to chtělo...

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        //
        // Create an instance of File for data.txt file.
        //
        File file = new File("data.txt");

        try {
            //
            // Create a new Scanner object which will read the data
            // from the file passed in. To check if there are more
            // line to read from it we check by calling the
            // scanner.hasNextLine() method. We then read line one
            // by one till all line is read.
            //
            Scanner scanner = new Scanner(file);
            while (scanner.hasNextLine()) {
                String lineFromFile = scanner.nextLine();
                try {
                    int numberFromFile = Integer.parseInt(lineFromFile.trim());
                    System.out.println(numberFromFile);
                } catch (NumberFormatException nfe) {
                    continue;
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny