listoffiles.java

来自「初期JAVA学习非常有用的资料。帮助深入了解API。特别是Applet。」· Java 代码 · 共 37 行

JAVA
37
字号
import java.util.*;import java.io.*;public class ListOfFiles implements Enumeration {    private String[] listOfFiles;    private int current = 0;    public ListOfFiles(String[] listOfFiles) {        this.listOfFiles = listOfFiles;    }    public boolean hasMoreElements() {        if (current < listOfFiles.length)            return true;        else            return false;    }    public Object nextElement() {        InputStream in = null;        if (!hasMoreElements())            throw new NoSuchElementException("No more files.");        else {            String nextElement = listOfFiles[current];            current++;            try {                in = new FileInputStream(nextElement);            } catch (FileNotFoundException e) {                System.err.println("ListOfFiles: Can't open " + nextElement);            }        }        return in;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?