Example usage for java.io File mkdir

List of usage examples for java.io File mkdir

Introduction

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

Prototype

public boolean mkdir() 

Source Link

Document

Creates the directory named by this abstract pathname.

Usage

From source file:net.idlesoft.android.apps.github.utils.GravatarCache.java

private static File ensure_directory(final String path) throws IOException {
    File root = Environment.getExternalStorageDirectory();
    if (!root.canWrite()) {
        throw new IOException("External storage directory is not writable");
    }/*from w  ww.  j  ava 2s  .  c  o  m*/
    final String[] parts = path.split("/");
    for (final String part : parts) {
        final File f = new File(root, part);
        if (!f.exists()) {
            final boolean created = f.mkdir();
            if (!created) {
                throw new IOException("Unable to create directory " + part);
            }
        } else {
            if (!f.isDirectory()) {
                throw new IOException("Unable to create directory " + part);
            }
        }
        root = f;
    }
    return root;
}

From source file:jmc.util.UtlFbComents.java

public static void getURLComentarios(String url, Long numComents) throws JMCException {

    File f = null;/*from  ww  w . j a  va  2s  . com*/

    try {
        Properties props = ConfigPropiedades.getProperties("props_config.properties");
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
        URL ur = new URL(
                "http://graph.facebook.com/comments?id=" + url + "&limit=" + numComents + "&filter=stream");
        HttpURLConnection cn = (HttpURLConnection) ur.openConnection();

        cn.setRequestProperty("user-agent", props.getProperty("navegador"));
        cn.setInstanceFollowRedirects(false);
        cn.setUseCaches(false);
        cn.connect();

        BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream()));
        String dirTempHtml = props.getProperty("archive_json") + "/";
        File fld = new File(dirTempHtml);

        boolean creado = fld.exists() ? true : fld.mkdir();

        if (creado) {
            String archFile = "archivo.json";
            String archivo = dirTempHtml + archFile;
            String linea = null;

            f = new File(archivo);
            BufferedWriter bw = new BufferedWriter(new FileWriter(f));
            while ((linea = br.readLine()) != null) {
                bw.append(linea);
            }
            bw.close();

            cn.disconnect();

            List<Fbcoment> lfb = Convertidor.getFbcomentObjects(1l, archivo);
            // Fbcoment.actComents(idContenido, lfb);

        } else {
            cn.disconnect();
        }

    } catch (IOException e) {
        throw new JMCException(e);
    }
}

From source file:jmc.util.UtlFbComents.java

public static void getComentarios(Long idContenido, Long numComents) throws JMCException {

    File f = null;//  w  w  w  .j a va  2  s  . c o  m

    try {
        Properties props = ConfigPropiedades.getProperties("props_config.properties");
        CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
        URL ur = new URL("http://graph.facebook.com/comments?id="
                + Contenido.getContenido("Where cont_id = '" + idContenido + "'").get(0).getEnlaceURL()
                + "&limit=" + numComents + "&filter=stream");
        HttpURLConnection cn = (HttpURLConnection) ur.openConnection();

        cn.setRequestProperty("user-agent", props.getProperty("navegador"));
        cn.setInstanceFollowRedirects(false);
        cn.setUseCaches(false);
        cn.connect();

        BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream()));
        String dirTempHtml = props.getProperty("archive_json") + "/";
        File fld = new File(dirTempHtml);

        boolean creado = fld.exists() ? true : fld.mkdir();

        if (creado) {
            String archFile = idContenido + ".json";
            String archivo = dirTempHtml + archFile;
            String linea = null;

            f = new File(archivo);
            BufferedWriter bw = new BufferedWriter(new FileWriter(f));
            while ((linea = br.readLine()) != null) {
                bw.append(linea);
            }
            bw.close();

            cn.disconnect();

            List<Fbcoment> lfb = Convertidor.getFbcomentObjects(idContenido, archivo);
            Fbcoment.actComents(idContenido, lfb);

        } else {
            cn.disconnect();
        }

    } catch (IOException e) {
        throw new JMCException(e);
    }
}

From source file:cn.org.once.cstack.utils.FilesUtils.java

/**
 * Create an upload directory//from w w  w. j  ava  2s .c  o  m
 *
 * @param server
 * @param uploadDir
 * @throws DockerJSONException
 */
public static void createUploadDir(Server server, String uploadDir) throws DockerJSONException {
    File uploadFolder = new File(uploadDir + "/uploadDir_" + server.getContainerID());
    if (!uploadFolder.exists()) {
        uploadFolder.mkdir();
    }
}

From source file:Main.java

public static void copy(InputStream stream, String path) throws IOException {

    final File file = new File(path);
    if (file.exists()) {
        file.delete();/*from  w ww .  j  a  v a  2  s. c  o  m*/
    }
    final File parentFile = file.getParentFile();

    if (!parentFile.exists()) {
        //noinspection ResultOfMethodCallIgnored
        parentFile.mkdir();
    }

    if (file.exists()) {
        return;
    }
    OutputStream myOutput = new FileOutputStream(path, true);

    byte[] buffer = new byte[1024];
    int length;
    while ((length = stream.read(buffer)) >= 0) {
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    stream.close();

}

From source file:edu.du.penrose.systems.util.HttpClientUtils.java

/**
 * Get file from URL, directories are created and files overwritten.
 * /*  w ww .j  a  v  a  2  s .c  o m*/
 * 
 * @deprecated use  org.apache.commons.io.FileUtils.copyURLToFile(URL, File)
 * @param requestUrl
 * @param outputPathAndFileName
 *
 * @return int request status code OR -1 if an exception occurred
 */
static public int getToFile(String requestUrl, String outputPathAndFileName) {
    int resultStatus = -1;

    File outputFile = new File(outputPathAndFileName);
    String outputPath = outputFile.getAbsolutePath().replace(outputFile.getName(), "");
    File outputDir = new File(outputPath);
    if (!outputDir.exists()) {
        outputDir.mkdir();
    }

    HttpClient client = new HttpClient();

    //   client.getState().setCredentials(
    //         new AuthScope("localhost", 7080, null ),
    //         new UsernamePasswordCredentials("nation", "nationPW") 
    //     );
    //   client.getParams().setAuthenticationPreemptive(true);

    HttpMethod method = new GetMethod(requestUrl);

    //   method.setDoAuthentication( true );   
    //  client.getParams().setAuthenticationPreemptive(true);

    // Execute and print response
    try {

        OutputStream os = new FileOutputStream(outputFile);

        client.executeMethod(method);
        InputStream is = method.getResponseBodyAsStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        byte[] bytes = new byte[8192]; // reading as chunk of 8192 bytes
        int count = bis.read(bytes);
        while (count != -1 && count <= 8192) {
            os.write(bytes, 0, count);
            count = bis.read(bytes);
        }
        bis.close();
        os.close();
        resultStatus = method.getStatusCode();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }

    return resultStatus;
}

From source file:juicebox.tools.utils.juicer.apa.APADataStack.java

private static File safeFolderCreation(String path) {
    File newFolder = new File(path);
    if (!newFolder.exists()) {
        boolean result = newFolder.mkdir();
        if (!result) {
            System.err.println("Error creating directory (data not saved): " + newFolder);
            return null;
        }//  w  w  w .  j a v  a 2s.com
    }
    return newFolder;
}

From source file:Main.java

public static File createSDDir(String dirName) throws IOException {
    File dir = new File(SDPATH + dirName);
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {

        System.out.println("createSDDir:" + dir.getAbsolutePath());
        System.out.println("createSDDir:" + dir.mkdir());
    }/* ww w  .j a  va 2s .  c o  m*/
    return dir;
}

From source file:com.parse.ParseKeyValueCache.java

static void initialize(File path) {
    if (!path.isDirectory() && !path.mkdir()) {
        throw new RuntimeException("Could not create ParseKeyValueCache directory");
    }/* w  w  w. ja va 2s.c  om*/
    directory = path;
}

From source file:io.github.blindio.prospero.core.browserdrivers.phantomjs.PhantomJSInstaller.java

static void installPhantomJS() {
    File tempArchive = null;/*from   w  w w  .  j a  v a  2  s . com*/
    try {
        tempArchive = File.createTempFile(PHANTOMJS_FILE_PREFIX, ArchiveFormat.getFileExtention());
        FileUtils.copyURLToFile(new URL(PhantomJSArchiveFile.getDownloadURL()), tempArchive);
        tempArchive.deleteOnExit();
        UnArchiver unarchiver = ArchiveFormat.getUnArchiver();
        unarchiver.setSourceFile(tempArchive);
        File destDir = new File(getPhantomJSInstallDirPath());
        if (!destDir.exists()) {
            destDir.mkdir();
        }
        unarchiver.setDestDirectory(destDir);
        unarchiver.extract();
    } catch (Exception e) {
        throw new ProsperoRuntimeAutomationException(e);
    }
}