Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.Collection;
  7. import java.util.Iterator;
  8. import java.util.List;
  9.  
  10. public class Bla {
  11.  
  12.     public static void main(String[] args) {
  13.         List<File> fileList = new ArrayList<File>();
  14.         addFiles(fileList, 10, ".txt");
  15.         writeOutFileList(fileList);
  16.     }
  17.    
  18.     static void addFiles(Collection<File> c, int index, String fileEnding) {
  19.         for(int i = 0; i < index; i++) {
  20.             c.add(new File(String.valueOf(i) + fileEnding));
  21.         }
  22.     }
  23.    
  24.     static void writeOutFileList(Collection<File> c) {
  25.         try {
  26.             BufferedWriter bw = null;
  27.             for(Iterator<File> it = c.iterator(); it.hasNext();) {
  28.                 bw = new BufferedWriter(new FileWriter(it.next()));
  29.                 bw.write("");
  30.                 it.remove();
  31.             }
  32.             bw.close();
  33.         } catch (IOException e) {
  34.             e.printStackTrace();
  35.         }
  36.     }
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement