Advertisement
silentkiler029

Azhar-FIle_io

Sep 29th, 2021
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Formatter;
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) {        
  7.         try {
  8.             Formatter frank = new Formatter("F:/frank.txt");
  9.             Formatter april = new Formatter("F:/april.txt");
  10.  
  11.             FileInputStream file = new FileInputStream("F:/script.txt");
  12.             Scanner sc = new Scanner(file);
  13.            
  14.             while( sc.hasNext() ) {
  15.                 String line = sc.nextLine();
  16.                 if( line.length() != 0 ) {
  17.                     if( line.charAt(0) == 'F' ) {
  18.                         frank.format("%s\r\n", line );
  19.                     }
  20.                     else if( line.charAt(0) == 'A' ) {
  21.                         april.format("%s\r\n", line);
  22.                     }
  23.                 }
  24.             }
  25.             sc.close();
  26.             frank.close();
  27.             april.close();
  28.         }
  29.         catch ( Exception e ) {
  30.             System.out.println(e);
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement