List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.igitras.codegen.common.utils.Utils.java
public static void createDirectory(File directory) { Assert.notNull(directory, "Directory cannot be null when creating directoryName in it."); if (!directory.exists()) { directory.mkdirs();/*www . j av a 2s .c o m*/ } else if (directory.isFile()) { directory.delete(); directory.mkdir(); } }
From source file:com.qwazr.database.TableManager.java
public static Class<? extends TableServiceInterface> load(ExecutorService executor, File dataDirectory) throws IOException { if (INSTANCE != null) throw new IOException("Already loaded"); File tableDir = new File(dataDirectory, SERVICE_NAME_TABLE); if (!tableDir.exists()) tableDir.mkdir(); try {/* w ww .j a va 2 s . co m*/ INSTANCE = new TableManager(executor, tableDir); return TableServiceImpl.class; } catch (ServerException e) { throw new RuntimeException(e); } }
From source file:jsdp.app.lotsizing.sS_jsdp.java
public static void plotCostFunction(int targetPeriod, double fixedOrderingCost, double proportionalOrderingCost, double holdingCost, double penaltyCost, Distribution[] distributions, double minDemand, double maxDemand, boolean printCostFunctionValues, boolean latexOutput, sS_StateSpaceSampleIterator.SamplingScheme samplingScheme, int maxSampleSize) { sS_BackwardRecursion recursion = new sS_BackwardRecursion(distributions, minDemand, maxDemand, fixedOrderingCost, proportionalOrderingCost, holdingCost, penaltyCost, samplingScheme, maxSampleSize);//from www.ja v a 2 s . c o m recursion.runBackwardRecursion(targetPeriod); XYSeries series = new XYSeries("(s,S) policy"); for (double i = sS_State.getMinInventory(); i <= sS_State.getMaxInventory(); i += sS_State.getStepSize()) { sS_StateDescriptor stateDescriptor = new sS_StateDescriptor(targetPeriod, sS_State.inventoryToState(i)); series.add(i, recursion.getExpectedCost(stateDescriptor)); if (printCostFunctionValues) System.out.println(i + "\t" + recursion.getExpectedCost(stateDescriptor)); } XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart( "(s,S) policy - period " + targetPeriod + " expected total cost", "Opening inventory level", "Expected total cost", xyDataset, PlotOrientation.VERTICAL, false, true, false); ChartFrame frame = new ChartFrame("(s,S) policy", chart); frame.setVisible(true); frame.setSize(500, 400); if (latexOutput) { try { XYLineChart lc = new XYLineChart("(s,S) policy", "Opening inventory level", "Expected total cost", new XYSeriesCollection(series)); File latexFolder = new File("./latex"); if (!latexFolder.exists()) { latexFolder.mkdir(); } Writer file = new FileWriter("./latex/graph.tex"); file.write(lc.toLatex(8, 5)); file.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.shareok.data.datahandlers.DataHandlersUtil.java
public static String getJobReportPath(String jobType, String jobId) { String shareokdataPath = getShareokdataPath(); String repoType = jobType.split("-")[2]; String filePath = shareokdataPath + File.separator + repoType; File file = new File(filePath); if (!file.exists()) { file.mkdir(); }// w ww.j av a 2s . c o m filePath += File.separator + jobType; file = new File(filePath); if (!file.exists()) { file.mkdir(); } filePath += File.separator + jobId; file = new File(filePath); if (!file.exists()) { file.mkdir(); } return filePath; }
From source file:com.phonegap.DirectoryManager.java
/** * Create directory on SD card.//from w w w . j a v a 2 s. c o m * * @param directoryName The name of the directory to create. * @return T=successful, F=failed */ protected static boolean createDirectory(String directoryName) { boolean status; // Make sure SD card exists if ((testSaveLocationExists()) && (!directoryName.equals(""))) { File path = Environment.getExternalStorageDirectory(); File newPath = constructFilePaths(path.toString(), directoryName); status = newPath.mkdir(); status = true; } // If no SD card or invalid dir name else { status = false; } return status; }
From source file:iplantappssplitter.IPlantAppsSplitter.java
/** * SetupInputOutput checks to see that we can find both the inputfile and * then makes the output directory. If something goes wrong with IO then * this function will exit.//w w w .j a va 2 s. com */ private static void SetupInputOutput() { File infile = new File(myArgs.getInputFile()); try { if (!infile.exists()) { throw new IOException("Input File: " + myArgs.getInputFile() + " not found."); } } catch (Exception e) { System.err.println(e.getMessage()); System.err.println("Exiting..."); System.exit(-1); } File dir = new File(myArgs.getOutputDirectory()); try { if (!dir.exists()) { Boolean status = dir.mkdir(); if (!status) { throw new IOException("Could not create directory: " + myArgs.getOutputDirectory()); } } } catch (Exception e) { System.err.println(e.getMessage()); System.err.println("Exiting..."); System.exit(-1); } }
From source file:net.algart.simagis.live.json.minimal.SimagisLiveUtils.java
public static JSONObject createThumbnail(File projectDir, File pyramidDir, String imageName, BufferedImage refImage) throws IOException, JSONException { final Path projectScope = projectDir.toPath(); final BufferedImage tmbImage = toThumbnailSize(refImage); final File thumbnailDir = new File(pyramidDir.getParentFile(), ".thumbnail"); thumbnailDir.mkdir(); final File refFile = File.createTempFile(imageName + ".", ".jpg", thumbnailDir); final File tmbFile = tmbImage != refImage ? File.createTempFile(imageName + ".tmb.", ".jpg", thumbnailDir) : refFile;/*from ww w . j a v a2 s . c o m*/ final JSONObject thumbnail = new JSONObject(); thumbnail.put("scope", "Project"); thumbnail.put("width", tmbImage.getWidth()); thumbnail.put("height", tmbImage.getHeight()); thumbnail.put("src", toRef(projectScope, tmbFile.toPath())); ImageIO.write(refImage, "JPEG", refFile); if (tmbFile != refFile) { thumbnail.put("ref", toRef(projectScope, refFile.toPath())); ImageIO.write(tmbImage, "JPEG", tmbFile); } return thumbnail; }
From source file:com.axelor.apps.tool.file.FileTool.java
/** * Copy all files and directories from a Folder to a destination Folder. * Must be called like: listAllFilesInFolder(srcFolderPath, "", srcFolderPath, * destFolderPath)//from w ww . j a v a 2 s .com * * @param currentFolder Used for the recursive called. * @param relatedPath Used for the recursive called. * @param sourceFolder Source directory. * @param destinationFolder Destination directory. * @param logger A logger. * @throws IOException */ public static void copyFolderToFolder(String sourceFolder, String destinationFolder) throws IOException { // Current Directory. File current = new File(sourceFolder); File destFile = new File(destinationFolder); if (!destFile.exists()) { destFile.mkdir(); } if (current.isDirectory()) { // List all files and folder in the current directory. File[] list = current.listFiles(); if (list != null) { // Read the files list. for (int i = 0; i < list.length; i++) { // Create current source File File tf = new File(sourceFolder + "/" + list[i].getName()); // Create current destination File File pf = new File(destinationFolder + "/" + list[i].getName()); if (tf.isDirectory() && !pf.exists()) { // If the file is a directory and does not exit in the // destination Folder. // Create the directory. pf.mkdir(); copyFolderToFolder(tf.getAbsolutePath(), pf.getAbsolutePath()); } else if (tf.isDirectory() && pf.exists()) { // If the file is a directory and exits in the // destination Folder. copyFolderToFolder(tf.getAbsolutePath(), pf.getAbsolutePath()); } else if (tf.isFile()) { // If it is a file. copy(sourceFolder + "/" + list[i].getName(), destinationFolder + "/" + list[i].getName()); } else { // Other cases. LOG.error("Error : Copy folder"); } } } } }
From source file:com.k_joseph.apps.multisearch.solr.AddCustomFieldsToSchema.java
/** * Overwrites the previous schema file with the newly generated * //from w ww .j a va2 s.co m * @param previousSchema currently used schema file * @param newSchema to be used instead of the previous */ private static void copyNewSchemaFileToPreviouslyUsed(String previousSchema, String newSchema) { File previousSchemaFile = new File(previousSchema); File newSchemaFile = new File(newSchema); if (previousSchemaFile.exists() && newSchemaFile.exists()) { String chartSearchBackUpPath = System.getProperty("user.home") + File.separator + ".multiSearch" + File.separator + "backup"; File chartSearchBackUp = new File(chartSearchBackUpPath); if (!chartSearchBackUp.exists()) { chartSearchBackUp.mkdir(); } previousSchemaFile.delete(); newSchemaFile.renameTo(previousSchemaFile); try { //Backing up the new schema file for easy retrieval after restarting or upgrading the module //TODO support an option clickat the UI where by the user can Reload the solrserver, //this would mean updating the schema file with back-up before the Reloading is done FileUtils.copyFileToDirectory(newSchemaFile, chartSearchBackUp); } catch (IOException e) { System.out.println("Error generated" + e); } } }
From source file:com.littcore.io.util.ZipUtils.java
public static void unzip(File srcZipFile, File targetFilePath, boolean isDelSrcFile) throws IOException { if (!targetFilePath.exists()) //? targetFilePath.mkdirs();//from w w w. j a v a 2s .c o m ZipFile zipFile = new ZipFile(srcZipFile); Enumeration fileList = zipFile.getEntries(); ZipEntry zipEntry = null; while (fileList.hasMoreElements()) { zipEntry = (ZipEntry) fileList.nextElement(); if (zipEntry.isDirectory()) //? { File subFile = new File(targetFilePath, zipEntry.getName()); if (!subFile.exists()) //?? subFile.mkdir(); continue; } else //? { File targetFile = new File(targetFilePath, zipEntry.getName()); if (logger.isDebugEnabled()) { logger.debug("" + targetFile.getName()); } if (!targetFile.exists()) { File parentPath = new File(targetFile.getParent()); if (!parentPath.exists()) //???????? parentPath.mkdirs(); //targetFile.createNewFile(); } InputStream in = zipFile.getInputStream(zipEntry); FileOutputStream out = new FileOutputStream(targetFile); int len; byte[] buf = new byte[BUFFERED_SIZE]; while ((len = in.read(buf)) != -1) { out.write(buf, 0, len); } out.close(); in.close(); } } zipFile.close(); if (isDelSrcFile) { boolean isDeleted = srcZipFile.delete(); if (isDeleted) { if (logger.isDebugEnabled()) { logger.debug(""); } } } }