Guest User

IcoGen.java

a guest
Jul 17th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1.  
  2. import javax.swing.*;
  3. import java.io.*;
  4.  
  5. public class IcoGen {
  6.     private String[] namesPNG, namesJPG, namesGIF;
  7.     public String[] combined;
  8.     public int cmbL;
  9.     private String dir;
  10.     private String line;
  11.     private String comm;
  12.     public ImageIcon[] icons;
  13.     public String[] ListFiles() {
  14.         File dir = new File("C:/Users/dubstep/Pictures/");
  15.         namesPNG = dir.list(new FilenameFilter() {
  16.             public boolean accept(File dir, String name) {
  17.                 return name.endsWith(".png");
  18.             }
  19.         });
  20.         namesJPG = dir.list(new FilenameFilter() {
  21.             public boolean accept(File dir, String name) {
  22.                 return name.endsWith(".jpg");
  23.             }
  24.         });
  25.         namesGIF = dir.list(new FilenameFilter() {
  26.             public boolean accept(File dir, String name) {
  27.                 return name.endsWith(".gif");
  28.             }
  29.         });
  30.         combined = new String[namesPNG.length + namesJPG.length + namesGIF.length];
  31.         int combLenght = namesPNG.length + namesJPG.length;
  32.         System.arraycopy(namesPNG, 0, combined, 0, namesPNG.length);
  33.         System.arraycopy(namesJPG, 0, combined, namesPNG.length, namesJPG.length);
  34.         System.arraycopy(namesGIF, 0, combined, combLenght, namesGIF.length);
  35.         cmbL = combined.length;
  36.         return combined;
  37.     }
  38.     public void writeToFile() throws IOException {
  39.  
  40.             BufferedWriter writeNow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("pics.txt"),"utf-8"));
  41.             for (int i = 0; i < cmbL; i++) {
  42.                 writeNow.write(combined[i]);
  43.                 writeNow.newLine();
  44.             } writeNow.close();
  45.     }
  46.     public Icon[] icoRead() throws IOException {
  47.         BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("pics.txt"),"utf-8"));
  48.         dir = "C/Users/dubstep/Pictures/";
  49.         for (int j = 0; j < cmbL; j++) {
  50.            line = read.readLine();
  51.            comm = dir+line;
  52.            icons[j] = new ImageIcon(this.getClass().getClassLoader().getResource(comm));
  53.         }
  54.         read.close();
  55.         return icons;
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment