Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list() 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.

Usage

From source file:com.bhuwan.eventregistration.business.boundary.EventRegistrationResource.java

@GET
public Response getAllEventData() throws FileNotFoundException, IOException {
    String path = getClass().getClassLoader().getResource("/eventdata/").getPath();
    File eventDataDirectory = new File(path);
    String[] list = eventDataDirectory.list();
    JsonArray array = new JsonArray();
    for (String fileName : list) {
        array.add(new JsonParser().parse(FileUtils.readFileToString(Paths.get(path + fileName).toFile())));
    }/* w ww. jav  a2 s .  c om*/
    return Response.ok(array.toString()).header("Access-Control-Allow-Origin", "*").build();
}

From source file:com.bhuwan.eventregistration.business.boundary.EventRegistrationResource.java

@GET
public Response getMaxEventId() throws FileNotFoundException, IOException {
    String path = getClass().getClassLoader().getResource("/eventdata/").getPath();
    File eventDataDirectory = new File(path);
    String[] list = eventDataDirectory.list();
    JsonArray array = new JsonArray();
    for (String fileName : list) {
        array.add(new JsonParser().parse(FileUtils.readFileToString(Paths.get(path + fileName).toFile())));
    }/*from ww w. j a  v a  2s  .  c om*/
    return Response.ok(array.toString()).header("Access-Control-Allow-Origin", "*").build();
}

From source file:it.evilsocket.dsploit.core.System.java

public static ArrayList<String> getAvailableSessionFiles() {
    ArrayList<String> files = new ArrayList<String>();
    File storage = new File(mStoragePath);

    if (storage != null && storage.exists()) {
        String[] children = storage.list();

        if (children != null && children.length > 0) {
            for (String child : children) {
                if (child.endsWith(".dss"))
                    files.add(child);/*from  w w w.  j ava 2  s  .co m*/
            }
        }
    }

    return files;
}

From source file:it.evilsocket.dsploit.core.System.java

public static ArrayList<String> getAvailableHijackerSessionFiles() {
    ArrayList<String> files = new ArrayList<String>();
    File storage = new File(mStoragePath);

    if (storage != null && storage.exists()) {
        String[] children = storage.list();

        if (children != null && children.length > 0) {
            for (String child : children) {
                if (child.endsWith(".dhs"))
                    files.add(child);/*from  w  ww  . java2s  .c  o  m*/
            }
        }
    }

    return files;
}

From source file:dk.statsbiblioteket.util.Files.java

private static void copyDirectory(File path, File toPath, boolean overwrite) throws IOException {
    log.trace("copyDirectory(" + path + ", " + toPath + ", " + overwrite + ") called");
    if (!toPath.exists()) {
        if (!toPath.mkdirs()) {
            throw new IOException("Unable to create or verify the existence" + " of the destination folder '"
                    + toPath.getAbsoluteFile() + "'");
        }/*from ww  w. j ava  2 s . c o m*/
    }
    if (!toPath.canWrite()) {
        throw new IOException("The destination folder '" + toPath.getAbsoluteFile() + "' is not writable");
    }

    for (String filename : path.list()) {
        File in = new File(path, filename);
        File out = new File(toPath, filename);
        innerCopy(in, out, overwrite);
    }
}

From source file:gov.nih.nci.cma.util.CmaSessionListener.java

public void sessionDestroyed(HttpSessionEvent event) {
    String sessionId = event.getSession().getId();
    System.out.println("Session destroyed cleaning cache for id=" + sessionId);

    BusinessCacheManager.getInstance().removeSessionCache(sessionId);

    Collection<Task> allTasks = PresentationCacheManager.getInstance().getAllSessionTasks(sessionId);
    BusinessCacheManager.getInstance().removeSessionCacheForTasks(allTasks);

    PresentationCacheManager.getInstance().removeSessionCache(sessionId);

    String gpUser = (String) event.getSession().getAttribute(PublicUserPool.PUBLIC_USER_NAME);
    PublicUserPool pool = (PublicUserPool) event.getSession().getAttribute(PublicUserPool.PUBLIC_USER_POOL);

    if (gpUser != null && pool != null) {
        pool.returnPublicUser(gpUser);//from w  ww . java  2 s  .  com
    }

    //clean up the temp files associated with this session
    String tmpDirStr = System.getProperty("java.io.tmpdir");
    System.out.println("Deleting files in tmpDir=" + tmpDirStr + " for session=" + sessionId);
    File tmpDir = new File(tmpDirStr);
    String[] tmpFiles = tmpDir.list();
    for (int i = 0; i < tmpFiles.length; i++) {
        String fileName = tmpFiles[i];
        if (fileName.startsWith(sessionId)) {
            //delete the file
            String fileNameToDelete = tmpDir + System.getProperty("file.separator") + fileName;
            try {
                File fileToDelete = new File(fileNameToDelete);
                System.out.println("Deleting file: " + fileNameToDelete);
                fileToDelete.delete();
            } catch (Exception ex) {
                log.error(ex);
            }
        }
    }
}

From source file:MainClass.java

protected void fillModel(SortTreeModel model, DefaultMutableTreeNode current) {
    MyFile pf = (MyFile) current.getUserObject();
    File f = pf.getFile();
    if (f.isDirectory()) {
        String files[] = f.list();
        for (int i = 0; i < files.length; i++) {
            if (files[i].startsWith("."))
                continue;
            MyFile tmp = new MyFile(pf, files[i]);
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp);
            model.insertNodeInto(node, current);
            if (tmp.getFile().isDirectory()) {
                fillModel(model, node);// w w  w.  j  a  v  a  2 s  . c om
            }
        }
    }
}

From source file:com.amazonaws.scala.ProjectGenerator.java

private void mkdir(File dir) throws IOException {
    if (dir.exists()) {
        for (String file : dir.list()) {
            delete(new File(dir, file));
        }/* w ww.  ja  v  a2s . c  o  m*/
    } else {
        if (!dir.mkdirs()) {
            throw new IOException("Error creating directory " + dir);
        }
    }
}

From source file:com.amazonaws.scala.ProjectGenerator.java

private void delete(File file) throws IOException {
    if (file.isDirectory()) {
        for (String f : file.list()) {
            delete(new File(file, f));
        }/*w w w . ja v a2 s.c  o m*/
    }
    if (!file.delete()) {
        throw new IOException("Could not delete " + file);
    }
}

From source file:eu.scape_project.arc2warc.Arc2WarcMigration.java

/**
 * Traverse the root directory recursively
 *
 * @param dirStructItem Root directory//from w  w  w  . java  2s  .co m
 * @throws FileNotFoundException
 * @throws IOException
 */
private void traverseDir(File dirStructItem) {
    if (dirStructItem.isDirectory()) {
        String[] children = dirStructItem.list();
        for (String child : children) {
            traverseDir(new File(dirStructItem, child));
        }
    } else {
        String filePath = dirStructItem.getAbsolutePath();
        if (RegexUtils.pathMatchesRegexFilter(filePath, config.getInputPathRegexFilter())) {
            migrate(dirStructItem);
        }
    }
}