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:Main.java

public static void copy(File src, File dest) throws IOException {

    if (src.isDirectory()) {

        //if directory not exists, create it
        if (!dest.exists()) {
            dest.mkdir();
            System.out.println("Directory copied from " + src + "  to " + dest);
        }/*from  w  w w . ja va2 s.  co m*/

        //list all the directory contents
        String files[] = src.list();

        for (int c = 0; c < files.length; c++) {
            //construct the src and dest file structure
            File srcFile = new File(src, files[c]);
            File destFile = new File(dest, files[c]);
            //recursive copy
            copy(srcFile, destFile);
        }

    } else {
        //if file, then copy it
        //Use bytes stream to support all file types
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);

        byte[] buffer = new byte[1024];

        int length;
        //copy the file content in bytes 
        while ((length = in.read(buffer)) > 0) {
            out.write(buffer, 0, length);
        }

        in.close();
        out.close();
        System.out.println("File copied from " + src + " to " + dest);
    }
}

From source file:com.qwazr.search.index.IndexManager.java

public synchronized static Class<? extends IndexServiceInterface> load(ExecutorService executorService,
        File dataDirectory) throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    File indexesDirectory = new File(dataDirectory, INDEXES_DIRECTORY);
    if (!indexesDirectory.exists())
        indexesDirectory.mkdir();
    if (!indexesDirectory.isDirectory())
        throw new IOException(
                "This name is not valid. No directory exists for this location: " + indexesDirectory.getName());
    INSTANCE = new IndexManager(executorService, indexesDirectory);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override// w  ww  .ja v  a  2  s . c o  m
        public void run() {
            INSTANCE.shutdown();
        }
    });
    return IndexServiceImpl.class;
}

From source file:bammerbom.ultimatecore.spongeapi.resources.classes.ErrorLogger.java

public static void log(Throwable t, String s) {
    String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(Calendar.getInstance().getTime());
    File dir = new File(r.getUC().getDataFolder() + "/Errors");
    if (!dir.exists()) {
        dir.mkdir();
    }/*  w w w.ja va  2s  .c o  m*/
    File file = new File(r.getUC().getDataFolder() + "/Errors", time + ".txt");
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    FileWriter outFile;
    try {
        outFile = new FileWriter(file);
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    PrintWriter out = new PrintWriter(outFile);
    out.println("=======================================");
    out.println("UltimateCore has run into an error ");
    out.println("Please report your error on dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    out.println("Spongeapi version: " + r.getGame().getMinecraftVersion() + " - "
            + r.getGame().getImplementationVersion());
    out.println("UltimateCore version: "
            + r.getGame().getPluginManager().getPlugin("UltimateCore").get().getVersion());
    out.println("Plugins loaded (" + r.getGame().getPluginManager().getPlugins().size() + "): "
            + Arrays.asList(r.getGame().getPluginManager().getPlugins()));
    out.println("Java version: " + System.getProperty("java.version"));
    out.println("OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", "
            + System.getProperty("os.version"));
    if (r.getGame().getServer().isPresent()) {
        out.println("Online mode: " + r.getGame().getServer().get().getOnlineMode());
    }
    out.println("Time: " + time);
    out.println("Error message: " + t.getMessage());
    out.println("UltimateCore message: " + s);
    out.println("=======================================");
    out.println("Stacktrace: \n" + ExceptionUtils.getStackTrace(t));
    out.println("=======================================");
    out.close();
    try {
        outFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //
    r.log(" ");
    r.log(TextColors.DARK_RED + "=========================================================");
    r.log(TextColors.RED + "UltimateCore has run into an error ");
    r.log(TextColors.RED + "Please report your error on ");
    r.log(TextColors.YELLOW + "http://dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket");
    r.log(TextColors.RED + "Include the file: ");
    r.log(TextColors.YELLOW + "plugins/UltimateCore/Errors/" + time + ".txt ");
    /*r.log(TextColors.RED + "Sponge version: " + Bukkit.getServer().getVersion());
     r.log(TextColors.RED + "UltimateCore version: " + Bukkit.getPluginManager().getPlugin("UltimateCore").getDescription().getVersion());
     r.log(TextColors.RED + "Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins()));
     r.log(TextColors.RED + "Java version: " + System.getProperty("java.version"));
     r.log(TextColors.RED + "OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version"));
     r.log(TextColors.RED + "Error message: " + t.getMessage());
     r.log(TextColors.RED + "UltimateCore message: " + s);*/
    r.log(TextColors.DARK_RED + "=========================================================");
    if (t instanceof Exception) {
        r.log(TextColors.RED + "Stacktrace: ");
        t.printStackTrace();
        r.log(TextColors.DARK_RED + "=========================================================");
    }
    r.log(" ");
}

From source file:com.opensearchserver.hadse.index.IndexCatalog.java

public final static ResponseEntity<?> create(String indexName, int shards, int replicas)
        throws HadseIndexException, JsonGenerationException, JsonMappingException, IOException {
    File indexDirectory = new File(Hadse.data_dir, indexName);
    if (indexDirectory.exists())
        return new ResponseEntity<Object>(HttpStatus.CONFLICT);
    if (!indexDirectory.mkdir())
        return new ResponseEntity<String>("Unable to create the index directory",
                HttpStatus.INTERNAL_SERVER_ERROR);
    IndexItem indexItem = IndexItem.get(indexName);
    for (int shard = 1; shard <= shards; shard++) {
        String shardName = Integer.toString(shard);
        ShardDef shardDef = ShardDef.write(indexDirectory, shardName, ClusterCatalog.nextShardCandidate());
        indexItem.add(ShardItem.load(shardDef, indexDirectory));
    }/* ww w . j  av a  2  s  .  com*/
    return new ResponseEntity<String>("Index created: " + indexName, HttpStatus.CREATED);
}

From source file:it.inserpio.mapillary.gopro.importer.GoProTimeLapseShotsMapillaryImporter.java

/**
 * @param bikeMateProGPXFileName// w w w . jav  a  2s .c  o m
 * @param goProImagesDirectoryName
 * @throws ParseException 
 * @throws IOException 
 * @throws GPXParsingException 
 * @throws XmlMappingException 
 * @throws CoordinatesNotFoundException 
 * @throws ImageReadException 
 * @throws ImageWriteException 
 */
public static void uploadToMapillary(String bikeMateProGPXFileName, String goProImagesDirectoryName)
        throws XmlMappingException, GPXParsingException, IOException, ParseException, ImageReadException,
        CoordinatesNotFoundException, ImageWriteException {
    // Get Date-Time Points from GPX file
    // ------------------------------------------------------------------------------------------
    GPXParser gpxParser = new BikeMateProGPXParser();

    List<GPXDateTimePoint> gpxDateTimePoints = gpxParser.parse(new File(bikeMateProGPXFileName));

    File goProImagesDirectory = new File(goProImagesDirectoryName);

    Assert.isTrue(goProImagesDirectory.isDirectory());

    File destinationDirectory = new File(
            goProImagesDirectory.getParent() + File.separator + "uploadable-images");

    if (!destinationDirectory.exists()) {
        destinationDirectory.mkdir();
    }

    File[] imageFiles = goProImagesDirectory.listFiles();

    // It sets gps coordinates for every GoPro time-lapse shot and upload to Mapillary
    // ------------------------------------------------------------------------------------------
    for (int imageIndex = 0; imageIndex < imageFiles.length; imageIndex++) {
        File imageFile = imageFiles[imageIndex];

        System.out.println("Managing image " + imageFile);

        Coordinates coordinates = Image2GeoMatcher.findCoordinatesByImageOriginalDateTime(imageFile,
                gpxDateTimePoints, 0);

        File modifiedImageFile = new File(destinationDirectory, imageFile.getName());

        EXIFPropertyWriter.setExifGPSTag(imageFile, modifiedImageFile, coordinates);

        UploadToMapillary.upload(modifiedImageFile, "", "", ""); // TODO upload not yet implemented
    }
}

From source file:BluemixUtils.java

private static void copyPhotosInTempDir(List<ClassifierUnit> all, int minSize) throws IOException {
    for (ClassifierUnit unit : all) {
        File dir = new File(TMP_DIR + File.separator + unit.getName());
        dir.mkdir();
        System.out.println("Copying files to " + dir.getAbsolutePath());
        File photosDir = new File(unit.getFolderWithImages());
        File[] photoes = photosDir.listFiles(filter);
        for (int i = 0; i < minSize; i++) {
            File source = photoes[i];
            System.out.println("Copying file " + photoes[i].getName());
            Files.copy(source.toPath(),
                    (new File(dir.getAbsolutePath() + File.separator + (i + 1)
                            + source.getName().substring(source.getName().indexOf(".")))).toPath(),
                    StandardCopyOption.REPLACE_EXISTING);
        }//from ww  w . ja  v  a  2s .  c o m

    }
}

From source file:com.qwazr.graph.GraphManager.java

public synchronized static Class<? extends GraphServiceInterface> load(ExecutorService executorService,
        File dataDirectory) throws IOException {
    if (INSTANCE != null)
        throw new IOException("Already loaded");
    File graphDirectory = new File(dataDirectory, SERVICE_NAME_GRAPH);
    if (!graphDirectory.exists())
        graphDirectory.mkdir();
    try {//from w ww  . j  a v a  2  s .c om
        INSTANCE = new GraphManager(executorService, graphDirectory);
        for (String name : INSTANCE.nameSet())
            INSTANCE.addNewInstance(name, INSTANCE.get(name));
        return GraphServiceImpl.class;
    } catch (ServerException | DatabaseException e) {
        throw new RuntimeException(e);
    }
}

From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java

public static void select(String infiledir, String outdir, int num_of_seqs, int subregion_length)
        throws IOException {
    File outdirFile = new File(outdir);
    if (!outdirFile.exists()) {
        outdirFile.mkdir();
    }//from   w w  w.  j  ava2s  .c  o  m
    File infile = new File(infiledir);

    // need to find the smallest sample size 
    int min_num_of_seqs = Integer.MAX_VALUE;
    if (infile.isDirectory()) {
        for (File f : infile.listFiles()) {
            IndexedSeqReader reader = new IndexedSeqReader(f);
            if (reader.getSeqIdSet().size() < min_num_of_seqs) {
                min_num_of_seqs = reader.getSeqIdSet().size();
            }
        }
    } else {
        IndexedSeqReader reader = new IndexedSeqReader(infile);
        if (reader.getSeqIdSet().size() < min_num_of_seqs) {
            min_num_of_seqs = reader.getSeqIdSet().size();
        }
    }

    if (num_of_seqs == 0) { // if user dis not specify the number, use the minimum sample size
        num_of_seqs = min_num_of_seqs;
    }
    if (min_num_of_seqs < num_of_seqs) {
        throw new IllegalArgumentException("The smallest sample size is " + min_num_of_seqs
                + ". Please modify the value for option num_selection");
    }

    String subregion = (subregion_length == 0) ? "" : "_" + subregion_length + "bp";

    if (infile.isDirectory()) {
        for (File f : infile.listFiles()) {
            File outfile = new File(outdir, "subset_" + subregion + f.getName());
            selectOne(f, num_of_seqs, subregion_length, outfile);
        }
    } else {
        String infile_prefix = infile.getName();
        String infile_suffix = "";
        int index = infile.getName().lastIndexOf(".");

        if (index != -1) {
            infile_prefix = infile.getName().substring(0, index);
            infile_suffix = infile.getName().substring(index);
        }
        File outfile = new File(outdir, infile_prefix + ".sub" + subregion + infile_suffix);
        selectOne(infile, num_of_seqs, subregion_length, outfile);
    }
}

From source file:Main.java

public static File createTempDir() throws IOException {
    File temp;

    temp = File.createTempFile("encfs-java-tmp", Long.toString(System.nanoTime()));
    if (!temp.delete()) {
        throw new IOException("Could not delete temporary file " + temp.getAbsolutePath());
    }//from   w  w  w. j ava 2 s  .c  o m

    if (!temp.mkdir()) {
        throw new IOException("Could not create temporary directory");
    }

    return temp;
}

From source file:BluemixUtils.java

public static void retriveFaces(ClassifierUnit unit) throws IOException {
    //curl -X POST -F "images_file=@prez.jpg" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces?api_key={api-key}&version=2016-05-20"
    File facesDir = new File(unit.getFolderWithImages() + "_faces");
    facesDir.mkdir();
    for (File image : new File(unit.getFolderWithImages()).listFiles()) {
        try {/*from ww w .ja  va  2  s .co m*/
            String command = "D:/curl/curl -X POST -F \"images_file=@" + image.getAbsolutePath()
                    + "\" \"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces?api_key={02a6297b759128a71e59e1a97c682826398584b4}&version=2016-05-20\"";
            String res = executeCmdCommand(command);
            FaceDetection s = new Gson().fromJson(res, FaceDetection.class);
            System.out.println(s.getBluemixImages().get(0).getFaces());
            BufferedImage in = ImageIO.read(image);
            for (Face face : s.getBluemixImages().get(0).getFaces()) {
                FaceLocation faceLoc = face.getFaceLocation();
                BufferedImage newIm = in.getSubimage(faceLoc.getLeft(), faceLoc.getTop(), faceLoc.getWidth(),
                        faceLoc.getHeight());
                File outputfile = new File(facesDir + File.separator + image.getName());
                ImageIO.write(newIm, "jpg", outputfile);
            }
        } catch (Exception ex) {
            Logger.getLogger("KrilovUtils.class").fine(ex.getMessage());
        }
    }

}