Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package t3;
- //import java.io.*;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class Exceptionss
- {
- // Read File Method -----------------------------------------------------------------
- public static void readFile(String fileName)
- {
- try
- {
- FileInputStream fis = new FileInputStream(fileName); // Входен стрийм от файл
- BufferedReader in = new BufferedReader(new InputStreamReader(fis)); // Буфер за прочетеното
- String tmp = null; // Временна променлива за разпечатване на съдържанието на файла
- while ((tmp = in.readLine()) != null)
- {
- System.out.println(tmp);
- }
- in.close();
- fis.close();
- }
- catch (FileNotFoundException e)
- {
- System.out.println("The File \"" + fileName + "\" does not exist! Unable to read it.");
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- // MAIN ////////////////////////////////////////////////////
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.print("Input file name : ");
- String fileName = input.nextLine();
- System.out.println();
- readFile(fileName);
- input.close();
- }// END MAIN
- }// END CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement