Azazavr

class Potoki (1 of 2)

Apr 8th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FilenameFilter;
  3. import java.util.Scanner;
  4.  
  5. public class Potoki implements Runnable {
  6.     public static void main(String[] args) {
  7.  
  8.         File[] fileList;
  9.         File F = new File("D:\\level2\\");
  10.         FilenameFilter only = new OnlyExt("txt");
  11.         fileList = F.listFiles();
  12.  
  13.         for (int i = 0; i < fileList.length; i++) {
  14.             if (fileList[i] == only) {
  15.                 openFile(fileList[i]);
  16.                 readFile();
  17.                 closeFile();
  18.             }
  19.         }
  20.  
  21.     }
  22.  
  23.     static Scanner x;
  24.  
  25.     public static void openFile(File file) {
  26.  
  27.         try {
  28.             x = new Scanner(new File(String.valueOf(file)));
  29.         } catch (Exception e) {
  30.             System.out.println("File not found");
  31.         }
  32.     }
  33.  
  34.     public static void readFile() {
  35.         while (x.hasNext()) {
  36.             String a = x.next(); //mail
  37.             String b = x.next(); //name
  38.             String c = x.next(); //date
  39.  
  40.             System.out.printf("%s %s %s\n", a, b, c);
  41.         }
  42.     }
  43.  
  44.     public static void closeFile() {
  45.         x.close();
  46.     }
  47.  
  48.     public void run() {
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment