Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.io.*;
- public class IcoGen {
- private String[] namesPNG, namesJPG, namesGIF;
- public String[] combined;
- public int cmbL;
- private String dir;
- private String line;
- private String comm;
- public ImageIcon[] icons;
- public String[] ListFiles() {
- File dir = new File("C:/Users/dubstep/Pictures/");
- namesPNG = dir.list(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".png");
- }
- });
- namesJPG = dir.list(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".jpg");
- }
- });
- namesGIF = dir.list(new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".gif");
- }
- });
- combined = new String[namesPNG.length + namesJPG.length + namesGIF.length];
- int combLenght = namesPNG.length + namesJPG.length;
- System.arraycopy(namesPNG, 0, combined, 0, namesPNG.length);
- System.arraycopy(namesJPG, 0, combined, namesPNG.length, namesJPG.length);
- System.arraycopy(namesGIF, 0, combined, combLenght, namesGIF.length);
- cmbL = combined.length;
- return combined;
- }
- public void writeToFile() throws IOException {
- BufferedWriter writeNow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("pics.txt"),"utf-8"));
- for (int i = 0; i < cmbL; i++) {
- writeNow.write(combined[i]);
- writeNow.newLine();
- } writeNow.close();
- }
- public Icon[] icoRead() throws IOException {
- BufferedReader read = new BufferedReader(new InputStreamReader(new FileInputStream("pics.txt"),"utf-8"));
- dir = "C/Users/dubstep/Pictures/";
- for (int j = 0; j < cmbL; j++) {
- line = read.readLine();
- comm = dir+line;
- icons[j] = new ImageIcon(this.getClass().getClassLoader().getResource(comm));
- }
- read.close();
- return icons;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment