Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4. public class Test {
  5.     public static void main(String[] args) throws Exception {
  6.         String filename =  args[0];
  7.         Test rTest = new Test();
  8.         rTest.throeException(rTest.readFile(filename));
  9.     }
  10.     public void throeException(String strE){
  11.         if(strE.contains("s") || strE.contains("u") || strE.contains("m") || strE.contains("a") || strE.contains("n")    ){
  12.              throw new IllegalArgumentException();
  13.          }
  14.     }
  15.     public String readFile(String file)
  16.     {
  17.         System.out.println(file);
  18.         StringBuilder stringBuilder = new StringBuilder();
  19.         Scanner scan;
  20.         try {
  21.             scan = new Scanner(new File(file));
  22.             while (scan.hasNextLine()){
  23.                 stringBuilder.append(scan.nextLine());
  24.             }
  25.             scan.close();
  26.         } catch (FileNotFoundException e) {
  27.             e.printStackTrace();
  28.         }
  29.         return stringBuilder.toString();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement